Example #1
0
 def run_tests(self):
     test_cases = []
     should_update_env = True
     for test in self.tests:
         desc = test['desc']
         name = test['name']
         index = test['id']
         test_case = TestCase(name, self.name)
         if '[.]' in desc:
             print('skipping test "{}"'.format(name))
             test_case.add_skipped_info(
                 message="Skipped test marked with [.]")
         else:
             test_output = StringIO()
             self.sp.logfile = test_output
             print('running test "{}"'.format(name))
             if should_update_env:
                 res = self.update_env(self.env_vars)
                 if res != BSTestRunner.SUCCESS:
                     print('failed to set environment variables')
                     break
                 res = self.pretest()
                 if res != BSTestRunner.SUCCESS:
                     print('failed to run pretest init')
                     break
                 should_update_env = False
             if name in self.mocks:
                 debug_print('setting up mocks')
                 self.mocks[name]['request_env'] = self.request_env
                 self.mocks[name]['setup']()
                 extra_env = mock_decorators.get_all_envs(name)
                 if extra_env is not None:
                     self.update_env(extra_env)
             t_start = time.time()
             result = self.run_test(index)
             if name in self.mocks:
                 debug_print('tearing down mocks')
                 try:
                     self.mocks[name]['teardown']()
                 except AssertionError:
                     debug_print('teardown assert failure')
                     result = BSTestRunner.FAIL
             t_stop = time.time()
             self.sp.logfile = None
             test_case.elapsed_sec = t_stop - t_start
             debug_print('test output was:')
             debug_print(test_output.getvalue())
             if result == BSTestRunner.SUCCESS:
                 test_case.stdout = filter(lambda c: ord(c) < 128,
                                           test_output.getvalue())
                 print('test "{}" passed'.format(name))
             else:
                 print('test "{}" failed'.format(name))
                 test_case.add_failure_info('Test failed',
                                            output=test_output.getvalue())
                 should_update_env = True
             test_output.close()
         test_cases += [test_case]
     return TestSuite(self.name, test_cases)
Example #2
0
 def run_tests(self):
     test_cases = []
     should_update_env = True
     for test in self.tests:
         desc = test['desc']
         name = test['name']
         index = test['id']
         test_case = TestCase(name, self.name)
         if '[.]' in desc:
             print('skipping test "{}"'.format(name))
             test_case.add_skipped_info(message="Skipped test marked with [.]")
         else:
             test_output = StringIO()
             self.sp.logfile = test_output
             print('running test "{}"'.format(name))
             if should_update_env:
                 res = self.update_env(self.env_vars)
                 if res != BSTestRunner.SUCCESS:
                     print('failed to set environment variables')
                     break;
                 should_update_env = False
             if name in self.mocks:
                 debug_print('setting up mocks')
                 self.mocks[name]['request_env'] = self.request_env
                 self.mocks[name]['setup']()
                 extra_env = mock_decorators.get_all_envs(name)
                 if extra_env is not None:
                     self.update_env(extra_env)
             t_start = time.time()
             result = self.run_test(index)
             if name in self.mocks:
                 debug_print('tearing down mocks')
                 try:
                     self.mocks[name]['teardown']()
                 except AssertionError:
                     debug_print('teardown assert failure')
                     result = BSTestRunner.FAIL
             t_stop = time.time()
             self.sp.logfile = None
             test_case.elapsed_sec = t_stop - t_start
             debug_print('test output was:')
             debug_print(test_output.getvalue())
             if result == BSTestRunner.SUCCESS:
                 test_case.stdout = test_output.getvalue()
                 print('test "{}" passed'.format(name))
             else:
                 print('test "{}" failed'.format(name))
                 test_case.add_failure_info('Test failed', output=test_output.getvalue())
                 should_update_env = True
             test_output.close()
         test_cases += [test_case];
     return TestSuite(self.name, test_cases)