From dccc1fcfafd37c6fd94ca766516cb4903b29668e Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 22 Mar 2010 00:15:53 +0000 Subject: [PATCH] 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. ........ --- Lib/test/test_unittest.py | 10 ++++++++++ Lib/unittest/__init__.py | 2 ++ Lib/unittest/__main__.py | 3 +++ Lib/unittest/case.py | 2 ++ Lib/unittest/loader.py | 1 + Lib/unittest/main.py | 2 ++ Lib/unittest/result.py | 8 +++----- Lib/unittest/runner.py | 2 ++ Lib/unittest/suite.py | 2 ++ 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 b4716a41cca..954b40a38ba 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 06fe55d08d5..8f77127a0d2 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 5bbda1c19be..5023610c820 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 0d224d8a757..ac5d1ecc36d 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 4e9e152869f..eea5c13366a 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 e6237b0f6ae..e04ec16ffbe 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 746967ec28a..91cf2183436 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 8773d0c5fe0..1729f1d098b 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 ddd83ae4c68..72b294962b9 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 1c1b600f7dd..736c20274d9 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)