From 74eac7607f3d3e955dead3432c8bde7b10e93c6d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 15 Jan 2010 17:16:50 +1300 Subject: Support SUBUNIT_FORMATTER environment variable. --- python/subunit/__init__.py | 13 +++++++++++++ python/subunit/run.py | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 6e8df90..754f974 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -1111,3 +1111,16 @@ class TestResultStats(unittest.TestResult): def wasSuccessful(self): """Tells whether or not this result was a success""" return self.failed_tests == 0 + + +def get_default_formatter(): + """Obtain the default formatter to write to. + + :return: A file-like object. + """ + formatter = os.getenv("SUBUNIT_FORMATTER") + if formatter is not None: + return os.popen(formatter, "w") + else: + return sys.stdout + diff --git a/python/subunit/run.py b/python/subunit/run.py index 2b90791..01c0b0e 100755 --- a/python/subunit/run.py +++ b/python/subunit/run.py @@ -22,7 +22,7 @@ import sys -from subunit import TestProtocolClient +from subunit import TestProtocolClient, get_default_formatter class SubunitTestRunner(object): @@ -41,6 +41,7 @@ if __name__ == '__main__': from unittest import TestProgram parser = optparse.OptionParser(__doc__) args = parser.parse_args()[1] - runner = SubunitTestRunner() + stream = get_default_formatter() + runner = SubunitTestRunner(stream) program = TestProgram(module=None, argv=[sys.argv[0]] + args, testRunner=runner) -- cgit v1.2.1 From 40935f3e52ab8a7695c871e1f8176aea70eef902 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 16 Jan 2010 16:36:40 +1300 Subject: Ignore SUBUNIT_FORMATTER if it is empty. --- python/subunit/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 754f974..751e853 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -1119,7 +1119,7 @@ def get_default_formatter(): :return: A file-like object. """ formatter = os.getenv("SUBUNIT_FORMATTER") - if formatter is not None: + if formatter is not None and formatter != "": return os.popen(formatter, "w") else: return sys.stdout -- cgit v1.2.1