def _run_suite(suite):
"""Run tests from a unittest.TestSuite-derived class."""
- runner = get_test_runner(sys.stdout, verbosity=verbose)
-
- # TODO: Remove this before merging (here for easy comparison with old impl)
- #runner = unittest.TextTestRunner(sys.stdout, verbosity=2, failfast=failfast)
+ runner = get_test_runner(sys.stdout,
+ verbosity=verbose,
+ capture_output=(junit_xml_list is not None))
result = runner.run(suite)
e.set('time', f'{time.perf_counter() - self.__start_time:0.6f}')
if capture:
- stdout = self._stdout_buffer.getvalue().rstrip()
- ET.SubElement(e, 'system-out').text = stdout
- stderr = self._stderr_buffer.getvalue().rstrip()
- ET.SubElement(e, 'system-err').text = stderr
+ if self._stdout_buffer is not None:
+ stdout = self._stdout_buffer.getvalue().rstrip()
+ ET.SubElement(e, 'system-out').text = stdout
+ if self._stderr_buffer is not None:
+ stderr = self._stderr_buffer.getvalue().rstrip()
+ ET.SubElement(e, 'system-err').text = stderr
for k, v in args.items():
if not k or not v:
return e
class QuietRegressionTestRunner:
- def __init__(self, stream):
+ def __init__(self, stream, buffer=False):
self.result = RegressionTestResult(stream, None, 0)
+ self.result.buffer = buffer
def run(self, test):
test(self.result)
return self.result
-def get_test_runner_class(verbosity):
+def get_test_runner_class(verbosity, buffer=False):
if verbosity:
return functools.partial(unittest.TextTestRunner,
resultclass=RegressionTestResult,
- buffer=True,
+ buffer=buffer,
verbosity=verbosity)
- return QuietRegressionTestRunner
+ return functools.partial(QuietRegressionTestRunner, buffer=buffer)
-def get_test_runner(stream, verbosity):
- return get_test_runner_class(verbosity)(stream)
+def get_test_runner(stream, verbosity, capture_output=False):
+ return get_test_runner_class(verbosity, capture_output)(stream)
if __name__ == '__main__':
class TestTests(unittest.TestCase):