changeset: 59880:2858cae540e4 branch: legacy-trunk parent: 59855:dbad1c0668c9 user: Michael Foord date: Mon Mar 22 00:06:30 2010 +0000 files: Lib/test/test_unittest.py Lib/unittest/__init__.py Lib/unittest/__main__.py Lib/unittest/case.py Lib/unittest/loader.py Lib/unittest/main.py Lib/unittest/result.py Lib/unittest/runner.py Lib/unittest/suite.py Lib/unittest/util.py description: Issue 7815. __unittest in module globals trims frames from reported stacktraces in unittest. diff -r dbad1c0668c9 -r 2858cae540e4 Lib/test/test_unittest.py --- a/Lib/test/test_unittest.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/test/test_unittest.py Mon Mar 22 00:06:30 2010 +0000 @@ -2084,6 +2084,16 @@ '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 -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/__init__.py --- a/Lib/unittest/__init__.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/__init__.py Mon Mar 22 00:06:30 2010 +0000 @@ -64,3 +64,5 @@ # deprecated _TextTestResult = TextTestResult + +__unittest = True diff -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/__main__.py --- a/Lib/unittest/__main__.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/__main__.py Mon Mar 22 00:06:30 2010 +0000 @@ -4,5 +4,8 @@ if sys.argv[0].endswith("__main__.py"): sys.argv[0] = "unittest" +__unittest = True + + from .main import main main(module=None) diff -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/case.py --- a/Lib/unittest/case.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/case.py Mon Mar 22 00:06:30 2010 +0000 @@ -12,6 +12,9 @@ strclass, safe_repr, sorted_list_difference, unorderable_list_difference ) +__unittest = True + + class SkipTest(Exception): """ Raise this exception in a test to skip it. diff -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/loader.py --- a/Lib/unittest/loader.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/loader.py Mon Mar 22 00:06:30 2010 +0000 @@ -10,6 +10,8 @@ from . import case, suite +__unittest = True + def _CmpToKey(mycmp): 'Convert a cmp= function into a key= function' diff -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/main.py --- a/Lib/unittest/main.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/main.py Mon Mar 22 00:06:30 2010 +0000 @@ -6,6 +6,8 @@ from . import loader, runner +__unittest = True + USAGE_AS_MAIN = """\ Usage: %(progName)s [options] [tests] diff -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/result.py --- a/Lib/unittest/result.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/result.py Mon Mar 22 00:06:30 2010 +0000 @@ -4,6 +4,8 @@ from . import util +__unittest = True + class TestResult(object): """Holder for test result information. @@ -98,11 +100,7 @@ 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 -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/runner.py --- a/Lib/unittest/runner.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/runner.py Mon Mar 22 00:06:30 2010 +0000 @@ -5,6 +5,8 @@ from . import result +__unittest = True + class _WritelnDecorator(object): """Used to decorate file-like objects with a handy 'writeln' method""" diff -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/suite.py --- a/Lib/unittest/suite.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/suite.py Mon Mar 22 00:06:30 2010 +0000 @@ -5,6 +5,8 @@ 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 -r dbad1c0668c9 -r 2858cae540e4 Lib/unittest/util.py --- a/Lib/unittest/util.py Sun Mar 21 20:30:30 2010 +0000 +++ b/Lib/unittest/util.py Mon Mar 22 00:06:30 2010 +0000 @@ -1,5 +1,8 @@ """Various utility functions.""" +__unittest = True + + def safe_repr(obj): try: return repr(obj)

AltStyle によって変換されたページ (->オリジナル) /