Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test = None
try:
test = self.prepare_test(file, variables)
logger.log_storage.test_start(file)
test.run()
info('Test ' + file + logger.green(' passed.'))
logger.log_storage.test_end(file, True)
return test, True
except SkipException:
info('Test ' + file + logger.yellow(' skipped.'))
logger.log_storage.test_end(file, True, end_comment='Skipped')
return test, True
except Exception as e:
warning('Test ' + file + logger.red(' failed: ') + str(e))
debug(traceback.format_exc())
logger.log_storage.test_end(file, False, str(e))
return test, False
def _run_test(self, file, variables):
test = None
try:
test = self.prepare_test(file, variables)
logger.log_storage.test_start(file)
test.run()
info('Test ' + file + logger.green(' passed.'))
logger.log_storage.test_end(file, True)
return test, True
except SkipException:
info('Test ' + file + logger.yellow(' skipped.'))
logger.log_storage.test_end(file, True, end_comment='Skipped')
return test, True
except Exception as e:
warning('Test ' + file + logger.red(' failed: ') + str(e))
debug(traceback.format_exc())
logger.log_storage.test_end(file, False, str(e))
return test, False
def _run_test(self, file, variables):
test = None
try:
test = self.prepare_test(file, variables)
logger.log_storage.test_start(file)
test.run()
info('Test ' + file + logger.green(' passed.'))
logger.log_storage.test_end(file, True)
return test, True
except SkipException:
info('Test ' + file + logger.yellow(' skipped.'))
logger.log_storage.test_end(file, True, end_comment='Skipped')
return test, True
except Exception as e:
warning('Test ' + file + logger.red(' failed: ') + str(e))
debug(traceback.format_exc())
logger.log_storage.test_end(file, False, str(e))
return test, False
def _run_include(test, file, include_file, ignore_errors):
"""
Run include as soon as it was included (run on include)
"""
try:
logger.log_storage.test_start(include_file['file'], test_type='include')
debug('Run include: ' + str(test))
res = test.run()
logger.log_storage.test_end(test.path, True, res, test_type='include')
return True
except SkipException:
info('Include ' + file + logger.yellow(' skipped.'))
logger.log_storage.test_end(file, True, end_comment='Skipped')
return True
except Exception as e:
logger.log_storage.test_end(test.path, False, str(e), test_type='include')
if not ignore_errors:
raise Exception('Include ' + file + ' failed: ' + str(e))
return False
def _run_finally(cls, test, file, result: bool):
if test and test.final:
logger.log_storage.test_start(file, test_type='{}_cleanup'.format(file))
try:
test.run_finally(result)
info('Test ' + file + ' [cleanup] ' + logger.green(' passed.'))
logger.log_storage.test_end(file, True, test_type='{} [cleanup]'.format(file))
except Exception as e:
warning('Test ' + file + ' [cleanup] ' + logger.red(' failed: ') + str(e))
debug(traceback.format_exc())
logger.log_storage.test_end(file, False, test_type='{} [cleanup]'.format(file))
def _run_finally(cls, test, file, result: bool):
if test and test.final:
logger.log_storage.test_start(file, test_type='{}_cleanup'.format(file))
try:
test.run_finally(result)
info('Test ' + file + ' [cleanup] ' + logger.green(' passed.'))
logger.log_storage.test_end(file, True, test_type='{} [cleanup]'.format(file))
except Exception as e:
warning('Test ' + file + ' [cleanup] ' + logger.red(' failed: ') + str(e))
debug(traceback.format_exc())
logger.log_storage.test_end(file, False, test_type='{} [cleanup]'.format(file))
def _run_include(test, file, include_file, ignore_errors):
"""
Run include as soon as it was included (run on include)
"""
try:
logger.log_storage.test_start(include_file['file'], test_type='include')
debug('Run include: ' + str(test))
res = test.run()
logger.log_storage.test_end(test.path, True, res, test_type='include')
return True
except SkipException:
info('Include ' + file + logger.yellow(' skipped.'))
logger.log_storage.test_end(file, True, end_comment='Skipped')
return True
except Exception as e:
logger.log_storage.test_end(test.path, False, str(e), test_type='include')
if not ignore_errors:
raise Exception('Include ' + file + ' failed: ' + str(e))
return False