diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-03-22 00:15:53 +0000 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-03-22 00:15:53 +0000 |
commit | 41dd690d80f1b663277fb33c74c300100c6376c1 (patch) | |
tree | 3a625b160cf8aa736b14f25d3dd5350d1a6095fa /Lib | |
parent | 7e301611cfae67f4a492c0b9a3f458c12b7f7328 (diff) | |
download | cpython-41dd690d80f1b663277fb33c74c300100c6376c1.tar.gz |
Merged revisions 79263 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79263 | michael.foord | 2010-03-21 19:06:30 -0500 (Sun, 21 Mar 2010) | 1 line
Issue 7815. __unittest in module globals trims frames from reported stacktraces in unittest.
........
Diffstat (limited to 'Lib')
-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 b4716a41cc..954b40a38b 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 06fe55d08d..8f77127a0d 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 5bbda1c19b..5023610c82 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 0d224d8a75..ac5d1ecc36 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 4e9e152869..eea5c13366 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 e6237b0f6a..e04ec16ffb 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 746967ec28..91cf218343 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 8773d0c5fe..1729f1d098 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 ddd83ae4c6..72b294962b 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 1c1b600f7d..736c20274d 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) |