Issue #22936: Allow showing local variables in unittest errors.

This commit is contained in:
Robert Collins 2015-03-06 13:46:35 +13:00
parent e37a1946c7
commit f0c819acd0
9 changed files with 118 additions and 32 deletions

View file

@ -126,7 +126,13 @@ class TextTestRunner(object):
resultclass = TextTestResult
def __init__(self, stream=None, descriptions=True, verbosity=1,
failfast=False, buffer=False, resultclass=None, warnings=None):
failfast=False, buffer=False, resultclass=None, warnings=None,
*, tb_locals=False):
"""Construct a TextTestRunner.
Subclasses should accept **kwargs to ensure compatibility as the
interface changes.
"""
if stream is None:
stream = sys.stderr
self.stream = _WritelnDecorator(stream)
@ -134,6 +140,7 @@ class TextTestRunner(object):
self.verbosity = verbosity
self.failfast = failfast
self.buffer = buffer
self.tb_locals = tb_locals
self.warnings = warnings
if resultclass is not None:
self.resultclass = resultclass
@ -147,6 +154,7 @@ class TextTestRunner(object):
registerResult(result)
result.failfast = self.failfast
result.buffer = self.buffer
result.tb_locals = self.tb_locals
with warnings.catch_warnings():
if self.warnings:
# if self.warnings is set, use it to filter all the warnings