def call_subunit_run(test_id, pretty, subunit): env = copy.deepcopy(os.environ) cmd_save_results = ['stestr', 'load', '--subunit'] if not os.path.isdir('.stestr'): commands.init_command() if pretty: # Use subunit run module cmd = ['python', '-m', 'subunit.run', test_id] ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) # Save subunit results via testr pfile = subprocess.Popen(cmd_save_results, env=env, stdin=ps.stdout, stdout=subprocess.PIPE) ps.stdout.close() # Transform output via subunit-trace proc = subprocess.Popen(['subunit-trace', '--no-failure-debug', '-f'], env=env, stdin=pfile.stdout) pfile.stdout.close() proc.communicate() return proc.returncode elif subunit: sstdout = io.BytesIO() subunit_run.main([sys.argv[0], test_id], sstdout) pfile = subprocess.Popen(cmd_save_results, env=env, stdin=subprocess.PIPE) pfile.communicate(input=sstdout.getvalue()) else: testtools_run.main([sys.argv[0], test_id], sys.stdout)
def call_subunit_run(test_id, pretty, subunit): if pretty: env = copy.deepcopy(os.environ) cmd = ["python", "-m", "subunit.run", test_id] ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) proc = subprocess.Popen(["subunit-trace", "--no-failure-debug", "-f"], env=env, stdin=ps.stdout) ps.stdout.close() proc.communicate() return proc.returncode elif subunit: subunit_run.main([sys.argv[0], test_id], sys.stdout) else: testtools_run.main([sys.argv[0], test_id], sys.stdout)
def call_subunit_run(test_id, pretty, subunit): if pretty: env = copy.deepcopy(os.environ) cmd = ['python', '-m', 'subunit.run', test_id] ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) proc = subprocess.Popen(['subunit-trace', '--no-failure-debug', '-f'], env=env, stdin=ps.stdout) ps.stdout.close() proc.communicate() return proc.returncode elif subunit: subunit_run.main([sys.argv[0], test_id], sys.stdout) else: testtools_run.main([sys.argv[0], test_id], sys.stdout)
def test_exits_zero_when_tests_fail(self): bytestream = io.BytesIO() stream = io.TextIOWrapper(bytestream, encoding="utf8") try: self.assertEqual(None, run.main( argv=["progName", "subunit.tests.test_run.TestSubunitTestRunner.FailingTest"], stdout=stream)) except SystemExit: self.fail("SystemExit raised") self.assertThat(bytestream.getvalue(), StartsWith(_b('\xb3')))
def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur, until_failure, color): if parallel: cmd = ['testr', 'run', '--parallel'] if concur: cmd.append('--concurrency=%s' % concur) else: cmd = ['testr', 'run'] if list_tests: cmd = ['testr', 'list-tests'] elif (subunit or pretty) and not until_failure: cmd.append('--subunit') elif not (subunit or pretty) and until_failure: cmd.append('--until-failure') cmd.append(regex) env = copy.deepcopy(os.environ) if pretty: subunit_trace_cmd = ['subunit-trace', '--no-failure-debug', '-f'] if color: subunit_trace_cmd.append('--color') # This workaround is necessary because of lp bug 1411804 it's super hacky # and makes tons of unfounded assumptions, but it works for the most part if (subunit or pretty) and until_failure: test_list = _get_test_list(regex, env) count = 0 failed = False if not test_list: print("No tests to run") exit(1) # If pretty or subunit output is desired manually loop forever over # test individually and generate the desired output in a linear series # this avoids 1411804 while retaining most of the desired behavior while True: for test in test_list: if pretty: cmd = ['python', '-m', 'subunit.run', test] ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) subunit_trace_cmd.append('--no-summary') proc = subprocess.Popen(subunit_trace_cmd, env=env, stdin=ps.stdout) ps.stdout.close() proc.communicate() if proc.returncode > 0: failed = True break else: try: subunit_run.main([sys.argv[0], test], sys.stdout) except SystemExit as e: if e > 0: print("Ran %s tests without failure" % count) exit(1) else: raise count = count + 1 if failed: print("Ran %s tests without failure" % count) exit(0) # If not until-failure special case call testr like normal elif pretty and not list_tests: ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) proc = subprocess.Popen(subunit_trace_cmd, env=env, stdin=ps.stdout) ps.stdout.close() else: proc = subprocess.Popen(cmd, env=env) proc.communicate() return_code = proc.returncode if slowest and not list_tests: print("\nSlowest Tests:\n") slow_proc = subprocess.Popen(['testr', 'slowest'], env=env) slow_proc.communicate() return return_code