Skip to content

Commit

Permalink
modified file saving so we save in the event of a test error.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresMWeber committed Mar 15, 2018
1 parent 0a2a257 commit f70c00f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,29 @@ def wrapped(self, *args, **kwargs):
return wrapped


def save_test_file(instance, save_file, func):
save_path = os.environ.get('A_SAVE_PATH', None)
timestamp = datetime.utcnow().strftime('%Y-%m-%d_T%H-%M-%S')
filename = '_'.join([instance.__class__.__name__, func.__name__, save_file, timestamp]) + '.mb'
path = os.path.join(*[f for f in [save_path, filename] if f])
rt.dcc.scene.fileop(rename=path)
rt.dcc.scene.fileop(save=True, type='mayaBinary')
print('Saving test result file for test %s in path %s' % (instance.__class__.__name__, path))


def auto_save_result(func):
@wraps(func)
def wrapped(self, *args, **kwargs):
save_file = os.environ.get('A_SAVE_PREFIX', None)
save_path = os.environ.get('A_SAVE_PATH', None)
func_return = func(self, *args, **kwargs)
try:
func_return = func(self, *args, **kwargs)
except Exception as e:
save_test_file(self, save_file, func)
raise e

if save_file:
timestamp = datetime.utcnow().strftime('%Y-%m-%d_T%H-%M-%S')
filename = '_'.join([self.__class__.__name__, func.__name__, save_file, timestamp]) + '.mb'
path = os.path.join(*[f for f in [save_path, filename] if f])
rt.dcc.scene.fileop(rename=path)
rt.dcc.scene.fileop(save=True, type='mayaBinary')
print('Saving test result file for test %s in path %s' % (self.__class__.__name__, path))
save_test_file(self, save_file, func)

return func_return

return wrapped

0 comments on commit f70c00f

Please sign in to comment.