Exemplo n.º 1
0
 def calculate_statistics(tests):
     from catcher.utils import logger
     ok = len([
         t for t in tests
         if t['status'] == 'OK' and t['comment'] != 'Skipped'
     ])
     skipped = len([t for t in tests if t['comment'] == 'Skipped'])
     fail = len(tests) - (ok + skipped)
     percent = (ok + skipped) / len(tests) * 100 if len(tests) > 0 else 0
     out_string = 'Test run {}.'.format(logger.blue(str(len(tests))))
     out_string += ' Success: ' + logger.green(str(ok)) + ', Fail: '
     if fail > 0:
         out_string += logger.red(str(fail))
     else:
         out_string += logger.green(str(fail))
     if skipped:
         out_string += ', Skipped: ' + logger.yellow(str(skipped))
     out_string += '. Total: '
     fun = logger.red
     if percent >= 100:
         fun = logger.green
     elif percent >= 66:
         fun = logger.light_green
     elif percent >= 33:
         fun = logger.yellow
     out_string += fun('{:.0f}%'.format(percent))
     return out_string
Exemplo n.º 2
0
 def _run_actions(self, step, action, action_object, variables, raise_stop,
                  ignore_errors) -> bool:
     action_name = get_action_name(action, action_object, variables)
     start = time.process_time()
     try:
         logger.log_storage.new_step(step, variables)
         action_object.check_skip(variables)
         self.variables = action_object.action(self.includes, variables)
         # repeat for run (variables were computed after name)
         action_name = get_action_name(action, action_object,
                                       self.variables)
         info('Step ' + action_name + get_timing(start) +
              logger.green(' OK'))
         logger.log_storage.step_end(step, self.variables)
         return True
     except StopException as e:  # stop a test without error
         if raise_stop:  # or raise error if configured
             logger.log_storage.step_end(step,
                                         variables,
                                         success=False,
                                         output=str(e))
             raise e
         debug('Skip ' + action_name + ' due to ' + str(e))
         info('Step ' + action_name + get_timing(start) +
              logger.green(' OK'))
         logger.log_storage.step_end(step,
                                     self.variables,
                                     success=True,
                                     output=str(e))
         return False  # stop current test
     except SkipException as e:  # skip this step
         info('Step ' + action_name + logger.yellow(' skipped'))
         logger.log_storage.step_end(step,
                                     self.variables,
                                     success=True,
                                     output=str(e))
         return True
     except Exception as e:
         if ignore_errors:  # continue actions & steps execution
             debug('Step ' + action_name + get_timing(start) +
                   logger.red(' failed') + ', but we ignore it')
             logger.log_storage.step_end(step, variables, success=True)
             return True
         else:
             info('Step ' + action_name + get_timing(start) +
                  logger.red(' failed: ') + str(e))
             debug(traceback.format_exc())
             logger.log_storage.step_end(step,
                                         variables,
                                         success=False,
                                         output=str(e))
             raise e
Exemplo n.º 3
0
 def _run_test(self,
               test: Test,
               global_variables: dict,
               output: str = 'full',
               test_type='test') -> bool:
     try:
         self.var_holder.prepare_variables(test, global_variables)
         logger.log_storage.test_start(test.file, test_type=test_type)
         test.check_ignored()
         with OptionalOutput(output == 'limited'):
             test.run()
         info(test_type.capitalize() + ' ' +
              cut_path(self.tests_path, test.file) +
              logger.green(' passed.'))
         logger.log_storage.test_end(test.file, True, test_type=test_type)
         return True
     except SkipException:
         info(test_type.capitalize() + ' ' +
              cut_path(self.tests_path, test.file) +
              logger.yellow(' skipped.'))
         logger.log_storage.test_end(test.file,
                                     True,
                                     end_comment='Skipped',
                                     test_type=test_type)
         return True
     except Exception as e:
         warning(test_type.capitalize() + ' ' +
                 cut_path(self.tests_path, test.file) +
                 logger.red(' failed: ') + str(e))
         debug(traceback.format_exc())
         logger.log_storage.test_end(test.file,
                                     False,
                                     str(e),
                                     test_type=test_type)
         return False
Exemplo n.º 4
0
 def print_summary(self, path):
     from catcher.utils import logger
     tests = [t for t in self._data if t.get('type') == 'test']
     out_string = self.calculate_statistics(tests)
     for test in tests:
         out_string += '\nTest {}: '.format(
             file_utils.cut_path(path, test['file']))
         # select only step's ends, which belongs to the current test (excluding registered includes run)
         step_finish_only = [
             o for o in test['output']
             if 'success' in o and o['nested'] == 0
         ]
         if test['status'] == 'OK' and test['comment'] != 'Skipped':
             out_string += logger.green('pass')
         elif test['comment'] == 'Skipped':
             out_string += logger.yellow('skipped')
         else:
             out_string += logger.red('fail') + ', on step {}'.format(
                 len(step_finish_only))
     logger.info(out_string)
Exemplo n.º 5
0
 def _run_finally(self, test, result: bool):
     if test and test.final:
         logger.log_storage.test_start(test.file,
                                       test_type='{}_cleanup'.format(
                                           test.file))
         try:
             test.run_finally(result)
             info('Test ' + cut_path(self.tests_path, test.file) +
                  ' [cleanup] ' + logger.green(' passed.'))
             logger.log_storage.test_end(test.file,
                                         True,
                                         test_type='{} [cleanup]'.format(
                                             test.file))
         except Exception as e:
             warning('Test ' + cut_path(self.tests_path, test.file) +
                     ' [cleanup] ' + logger.red(' failed: ') + str(e))
             debug(traceback.format_exc())
             logger.log_storage.test_end(test.file,
                                         False,
                                         test_type='{} [cleanup]'.format(
                                             test.file))