def tracker_test_main(): """Entry point which must be called by all functional test modules.""" if cfg.tests_verbose(): # Output all logs to stderr logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) else: # Output only messages from Tracker daemons under test. See # tracker.git/utils/trackertestutils/dbusdaemon.py. handler_stderr = logging.StreamHandler(stream=sys.stderr) handler_stderr.addFilter(logging.Filter('sandbox-session-bus.stderr')) handler_stdout = logging.StreamHandler(stream=sys.stderr) handler_stdout.addFilter(logging.Filter('sandbox-session-bus.stdout')) logging.basicConfig(level=logging.INFO, handlers=[handler_stderr, handler_stdout], format='%(message)s') runner = None if cfg.tap_protocol_enabled(): try: from tap import TAPTestRunner runner = TAPTestRunner() runner.set_stream(True) except ImportError as e: log.error('No TAP test runner found: %s', e) raise ut.main(testRunner=runner, failfast=True, verbosity=2)
def _create_test_runner(self, component: str) -> None: """ Creates the test runner to use for test execution. Args: component: Name of the component to test. """ logger = logging.getLogger('suisei.sde') logger.debug('Creating test runner for component %s...', component) try: from tap import TAPTestRunner self._test_runner = TAPTestRunner( verbosity=self._application.Configuration.get_ut_verbosity( component)) self._test_runner.set_outdir( self._application.Configuration.get_ut_outdir(component)) self._test_runner.set_format( self._application.Configuration.get_ut_log_format(component)) except ImportError: logger.warning('The TAP test runner is not installed on the host ' 'system, falling back to the default unit test ' 'runner.') self._test_runner = unittest.TextTestRunner( verbosity=self._application.Configuration.get_ut_verbosity( component)) logger.debug('Test runner created successfully.')
def tracker_test_main(): """Entry point that all functional-test modules must call.""" if cfg.tests_verbose(): # Output all logs to stderr logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) else: # Output some messages from D-Bus daemon to stderr by default. In practice, # only errors and warnings should be output here unless the environment # contains G_MESSAGES_DEBUG=. handler_stderr = logging.StreamHandler(stream=sys.stderr) handler_stderr.addFilter(logging.Filter('sandbox-session-bus.stderr')) handler_stdout = logging.StreamHandler(stream=sys.stderr) handler_stdout.addFilter(logging.Filter('sandbox-session-bus.stdout')) logging.basicConfig(level=logging.INFO, handlers=[handler_stderr, handler_stdout], format='%(message)s') runner = None if cfg.tap_protocol_enabled(): try: from tap import TAPTestRunner runner = TAPTestRunner() runner.set_stream(True) except ImportError as e: log.error('No TAP test runner found: %s', e) raise ut.main(testRunner=runner, verbosity=2)
def test_runner_stream_to_devnull_for_streaming(self): previous_streaming = _tracker.streaming previous_stream = _tracker.stream runner = TAPTestRunner() runner.set_stream(True) self.assertTrue(runner.stream.stream.name, os.devnull) _tracker.streaming = previous_streaming _tracker.stream = previous_stream
def test_runner_sets_tracker_for_streaming(self): """The tracker is set for streaming mode.""" previous_streaming = _tracker.streaming previous_stream = _tracker.stream runner = TAPTestRunner() runner.set_stream(True) self.assertTrue(_tracker.streaming) self.assertTrue(_tracker.stream, sys.stdout) _tracker.streaming = previous_streaming _tracker.stream = previous_stream
def run_suite(suite): if cfg.tap_protocol_enabled(): try: from tap import TAPTestRunner runner = TAPTestRunner() runner.set_stream(True) except ImportError as e: log.error('No TAP test runner found: %s', e) raise else: runner = ut.TextTestRunner(verbosity=1) result = runner.run(suite) sys.exit(not result.wasSuccessful())
setup.wait() if setup.returncode != 0: raise Exception('Setup failed') def run_teardowns(tests): teardowns = [] for test in tests: test_dir = path_from_name(test[0], 'plain') if os.path.isfile(os.path.join(test_dir, 'teardown.sh')): teardowns.append( subprocess.Popen('./teardown.sh', cwd=test_dir, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)) for teardown in teardowns: teardown.wait() if __name__ == '__main__': tests = get_test_cases() run_setups(tests) suite = unittest.TestSuite() for test in tests: suite.addTest(test[1]()) runner = TAPTestRunner() runner.set_format('{method_name}') runner.set_stream(True) runner.run(suite) run_teardowns(tests)
def execute(self): runner = TAPTestRunner() runner.set_outdir('logs/TAP/') runner.set_format('{method_name} and {short_description}') runner.set_combined(True) runner.run(self.suite)
) args = argparser.parse_args() loader = unittest.TestLoader() start_dir = args.start_dir pattern = args.pattern failfast = args.failfast test_case = args.test_case if test_case: sys.path.append(start_dir) tests = loader.loadTestsFromName(test_case) elif pattern: tests = loader.discover(start_dir, pattern) else: # This will never happen because the mutual exclusion group has the # `required` parameter set to True. So one or the other must be set or # else it will fail to parse. sys.exit(1) if tests.countTestCases() < 1: print("No tests matching '%s' found in '%s'" % (pattern, start_dir)) sys.exit(1) runner = TAPTestRunner(failfast=failfast) runner.set_stream(True) runner.set_format('{method_name}') sys.exit(0 if runner.run(tests).wasSuccessful() else 1)
def test_has_tap_test_result(self): runner = TAPTestRunner() self.assertEqual(runner.resultclass, TAPTestResult)