summaryrefslogtreecommitdiffstats
path: root/Lib/unittest.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-07 09:21:06 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-07 09:21:06 (GMT)
commitd0a962506bd69d94dcd740a9555140d09b8cf2b5 (patch)
tree7d6c988c264deacfb154fd97871772335e756de1 /Lib/unittest.py
parent15c5ce936f8dd2d83a02707efbeb88531f7514af (diff)
downloadcpython-d0a962506bd69d94dcd740a9555140d09b8cf2b5.zip
cpython-d0a962506bd69d94dcd740a9555140d09b8cf2b5.tar.gz
cpython-d0a962506bd69d94dcd740a9555140d09b8cf2b5.tar.bz2
Patch #787789: allow to pass custom TestRunner instances to unittest's
main() function.
Diffstat (limited to 'Lib/unittest.py')
-rw-r--r--Lib/unittest.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py
index abd9223..0d69f52 100644
--- a/Lib/unittest.py
+++ b/Lib/unittest.py
@@ -776,7 +776,8 @@ Examples:
in MyTestCase
"""
def __init__(self, module='__main__', defaultTest=None,
- argv=None, testRunner=None, testLoader=defaultTestLoader):
+ argv=None, testRunner=TextTestRunner,
+ testLoader=defaultTestLoader):
if type(module) == type(''):
self.module = __import__(module)
for part in module.split('.')[1:]:
@@ -826,9 +827,16 @@ Examples:
self.module)
def runTests(self):
- if self.testRunner is None:
- self.testRunner = TextTestRunner(verbosity=self.verbosity)
- result = self.testRunner.run(self.test)
+ if isinstance(self.testRunner, (type, types.ClassType)):
+ try:
+ testRunner = self.testRunner(verbosity=self.verbosity)
+ except TypeError:
+ # didn't accept the verbosity argument
+ testRunner = self.testRunner()
+ else:
+ # it is assumed to be a TestRunner instance
+ testRunner = self.testRunner
+ result = testRunner.run(self.test)
sys.exit(not result.wasSuccessful())
main = TestProgram