diff options
author | Robert Collins <rbtcollins@hp.com> | 2015-03-06 00:46:35 (GMT) |
---|---|---|
committer | Robert Collins <rbtcollins@hp.com> | 2015-03-06 00:46:35 (GMT) |
commit | f0c819acd0f85eafe12a7ff706650cb39d3fbf34 (patch) | |
tree | bfd78fdedfd364995c6c707ac1f137cb763597e9 /Lib/unittest/main.py | |
parent | e37a1946c7196169b8d3117f65391a12bb8d97f7 (diff) | |
download | cpython-f0c819acd0f85eafe12a7ff706650cb39d3fbf34.zip cpython-f0c819acd0f85eafe12a7ff706650cb39d3fbf34.tar.gz cpython-f0c819acd0f85eafe12a7ff706650cb39d3fbf34.tar.bz2 |
Issue #22936: Allow showing local variables in unittest errors.
Diffstat (limited to 'Lib/unittest/main.py')
-rw-r--r-- | Lib/unittest/main.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py index 486d39f..b209a3a 100644 --- a/Lib/unittest/main.py +++ b/Lib/unittest/main.py @@ -58,7 +58,7 @@ class TestProgram(object): def __init__(self, module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=loader.defaultTestLoader, exit=True, verbosity=1, failfast=None, catchbreak=None, - buffer=None, warnings=None): + buffer=None, warnings=None, *, tb_locals=False): if isinstance(module, str): self.module = __import__(module) for part in module.split('.')[1:]: @@ -73,6 +73,7 @@ class TestProgram(object): self.catchbreak = catchbreak self.verbosity = verbosity self.buffer = buffer + self.tb_locals = tb_locals if warnings is None and not sys.warnoptions: # even if DeprecationWarnings are ignored by default # print them anyway unless other warnings settings are @@ -159,7 +160,9 @@ class TestProgram(object): parser.add_argument('-q', '--quiet', dest='verbosity', action='store_const', const=0, help='Quiet output') - + parser.add_argument('--locals', dest='tb_locals', + action='store_true', + help='Show local variables in tracebacks') if self.failfast is None: parser.add_argument('-f', '--failfast', dest='failfast', action='store_true', @@ -231,10 +234,18 @@ class TestProgram(object): self.testRunner = runner.TextTestRunner if isinstance(self.testRunner, type): try: - testRunner = self.testRunner(verbosity=self.verbosity, - failfast=self.failfast, - buffer=self.buffer, - warnings=self.warnings) + try: + testRunner = self.testRunner(verbosity=self.verbosity, + failfast=self.failfast, + buffer=self.buffer, + warnings=self.warnings, + tb_locals=self.tb_locals) + except TypeError: + # didn't accept the tb_locals argument + testRunner = self.testRunner(verbosity=self.verbosity, + failfast=self.failfast, + buffer=self.buffer, + warnings=self.warnings) except TypeError: # didn't accept the verbosity, buffer or failfast arguments testRunner = self.testRunner() |