def test_max_failures_ignored_if_unset(self): r = Runner() r.args.tests = ['typ.tests.runner_test.FailureTests'] r.args.jobs = 1 r.args.typ_max_failures = None r.context = True r.run()
def test_max_failures_fail_if_equal(self): r = Runner() r.args.tests = ['typ.tests.runner_test.FailureTests'] r.args.jobs = 1 r.args.typ_max_failures = 1 r.context = True with self.assertRaises(RuntimeError): r.run()
def test_max_failures_pass_if_under(self): r = Runner() r.args.tests = [ 'typ.tests.runner_test.ContextTests', 'typ.tests.runner_test.FAilureTests' ] r.args.jobs = 1 r.args.typ_max_failures = 2 r.context = True r.run()
def test_failing_load_test(self): h = Host() orig_wd = h.getcwd() tmpdir = None try: tmpdir = h.mkdtemp() h.chdir(tmpdir) h.write_text_file( 'load_test.py', d("""\ import unittest def load_tests(_, _2, _3): assert False """)) test_set = TestSet(MockArgs()) test_set.parallel_tests = [TestInput('load_test.BaseTest.test_x')] r = Runner() r.args.jobs = 1 ret, _, trace = r.run(test_set) self.assertEqual(ret, 1) self.assertIn('BaseTest', trace['traceEvents'][0]['args']['err']) finally: h.chdir(orig_wd) if tmpdir: h.rmtree(tmpdir)
def test_missing_name(self): test_set = TestSet(MockArgs()) test_set.parallel_tests = [TestInput('nonexistent test')] r = Runner() r.args.jobs = 1 ret, _, _ = r.run(test_set) self.assertEqual(ret, 1)
def test_failing_load_test(self): h = Host() orig_wd = h.getcwd() tmpdir = None try: tmpdir = h.mkdtemp() h.chdir(tmpdir) h.write_text_file('load_test.py', d("""\ import unittest def load_tests(_, _2, _3): assert False """)) test_set = TestSet() test_set.parallel_tests = [TestInput('load_test.BaseTest.test_x')] r = Runner() r.args.jobs = 1 ret, _, trace = r.run(test_set) self.assertEqual(ret, 1) self.assertIn('Failed to load "load_test.BaseTest.test_x" in ' 'run_one_test', trace['traceEvents'][0]['args']['err']) finally: h.chdir(orig_wd) if tmpdir: h.rmtree(tmpdir)
def test_context(self): r = Runner() r.args.tests = ['typ.tests.runner_test.ContextTests'] r.context = {'foo': 'bar'} r.setup_fn = _setup_process r.teardown_fn = _teardown_process r.win_multiprocessing = WinMultiprocessing.importable ret, _, _ = r.run() self.assertEqual(ret, 0)
def test_exception_in_teardown(self): r = Runner() r.args.tests = ['typ.tests.runner_test.ContextTests'] r.context = {'foo': 'bar'} r.setup_fn = _setup_process r.teardown_fn = _teardown_throws r.win_multiprocessing = WinMultiprocessing.importable ret, _, _ = r.run() self.assertEqual(ret, 0) self.assertEqual(r.final_responses[0][2].message, 'exception in teardown')