diff options
-rw-r--r-- | Lib/test/test_unittest.py | 10 | ||||
-rw-r--r-- | Lib/unittest/__init__.py | 2 | ||||
-rw-r--r-- | Lib/unittest/__main__.py | 3 | ||||
-rw-r--r-- | Lib/unittest/case.py | 2 | ||||
-rw-r--r-- | Lib/unittest/loader.py | 1 | ||||
-rw-r--r-- | Lib/unittest/main.py | 2 | ||||
-rw-r--r-- | Lib/unittest/result.py | 8 | ||||
-rw-r--r-- | Lib/unittest/runner.py | 2 | ||||
-rw-r--r-- | Lib/unittest/suite.py | 2 | ||||
-rw-r--r-- | Lib/unittest/util.py | 3 |
10 files changed, 30 insertions, 5 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index b4716a4..954b40a 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -2096,6 +2096,16 @@ class Test_TestResult(TestCase): 'Tests getDescription() for a method with a longer ' 'docstring.')) + def testStackFrameTrimming(self): + class Frame(object): + class tb_frame(object): + f_globals = {} + result = unittest.TestResult() + self.assertFalse(result._is_relevant_tb_level(Frame)) + + Frame.tb_frame.f_globals['__unittest'] = True + self.assertTrue(result._is_relevant_tb_level(Frame)) + classDict = dict(unittest.TestResult.__dict__) for m in ('addSkip', 'addExpectedFailure', 'addUnexpectedSuccess', '__init__'): diff --git a/Lib/unittest/__init__.py b/Lib/unittest/__init__.py index 06fe55d..8f77127 100644 --- a/Lib/unittest/__init__.py +++ b/Lib/unittest/__init__.py @@ -64,3 +64,5 @@ from .runner import TextTestRunner, TextTestResult # deprecated _TextTestResult = TextTestResult + +__unittest = True diff --git a/Lib/unittest/__main__.py b/Lib/unittest/__main__.py index 5bbda1c..5023610 100644 --- a/Lib/unittest/__main__.py +++ b/Lib/unittest/__main__.py @@ -4,5 +4,8 @@ import sys if sys.argv[0].endswith("__main__.py"): sys.argv[0] = "unittest" +__unittest = True + + from .main import main main(module=None) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 0d224d8..ac5d1ec 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -11,6 +11,8 @@ from . import result from .util import (strclass, safe_repr, sorted_list_difference, unorderable_list_difference) +__unittest = True + class SkipTest(Exception): """ diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py index 4e9e152..eea5c13 100644 --- a/Lib/unittest/loader.py +++ b/Lib/unittest/loader.py @@ -10,6 +10,7 @@ from fnmatch import fnmatch from . import case, suite, util +__unittest = True # what about .pyc or .pyo (etc) # we would need to avoid loading the same tests multiple times diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py index e6237b0..e04ec16 100644 --- a/Lib/unittest/main.py +++ b/Lib/unittest/main.py @@ -6,6 +6,8 @@ import types from . import loader, runner +__unittest = True + USAGE_AS_MAIN = """\ Usage: %(progName)s [options] [tests] diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py index 746967e..91cf218 100644 --- a/Lib/unittest/result.py +++ b/Lib/unittest/result.py @@ -4,6 +4,8 @@ import traceback from . import util +__unittest = True + class TestResult(object): """Holder for test result information. @@ -98,11 +100,7 @@ class TestResult(object): return ''.join(traceback.format_exception(exctype, value, tb)) def _is_relevant_tb_level(self, tb): - globs = tb.tb_frame.f_globals - is_relevant = '__name__' in globs and \ - globs["__name__"].startswith("unittest") - del globs - return is_relevant + return '__unittest' in tb.tb_frame.f_globals def _count_relevant_tb_levels(self, tb): length = 0 diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py index 8773d0c..1729f1d 100644 --- a/Lib/unittest/runner.py +++ b/Lib/unittest/runner.py @@ -5,6 +5,8 @@ import time from . import result +__unittest = True + class _WritelnDecorator(object): """Used to decorate file-like objects with a handy 'writeln' method""" diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py index ddd83ae..72b2949 100644 --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -5,6 +5,8 @@ import sys from . import case from . import util +__unittest = True + class BaseTestSuite(object): """A simple test suite that doesn't provide class or module shared fixtures. diff --git a/Lib/unittest/util.py b/Lib/unittest/util.py index 1c1b600..736c202 100644 --- a/Lib/unittest/util.py +++ b/Lib/unittest/util.py @@ -1,5 +1,8 @@ """Various utility functions.""" +__unittest = True + + def safe_repr(obj): try: return repr(obj) |