Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dccc1fc

Browse files
committed
Merged revisions 79263 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent a6884fc commit dccc1fc

10 files changed

Lines changed: 30 additions & 5 deletions

File tree

Lib/test/test_unittest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,16 @@ def testGetDescriptionWithMultiLineDocstring(self):
20962096
'Tests getDescription() for a method with a longer '
20972097
'docstring.'))
20982098

2099+
def testStackFrameTrimming(self):
2100+
class Frame(object):
2101+
class tb_frame(object):
2102+
f_globals = {}
2103+
result = unittest.TestResult()
2104+
self.assertFalse(result._is_relevant_tb_level(Frame))
2105+
2106+
Frame.tb_frame.f_globals['__unittest'] = True
2107+
self.assertTrue(result._is_relevant_tb_level(Frame))
2108+
20992109
classDict = dict(unittest.TestResult.__dict__)
21002110
for m in ('addSkip', 'addExpectedFailure', 'addUnexpectedSuccess',
21012111
'__init__'):

Lib/unittest/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ def testMultiply(self):
6464

6565
# deprecated
6666
_TextTestResult = TextTestResult
67+
68+
__unittest = True

Lib/unittest/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
if sys.argv[0].endswith("__main__.py"):
55
sys.argv[0] = "unittest"
66

7+
__unittest = True
8+
9+
710
from .main import main
811
main(module=None)

Lib/unittest/case.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from .util import (strclass, safe_repr, sorted_list_difference,
1212
unorderable_list_difference)
1313

14+
__unittest = True
15+
1416

1517
class SkipTest(Exception):
1618
"""

Lib/unittest/loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from . import case, suite, util
1212

13+
__unittest = True
1314

1415
# what about .pyc or .pyo (etc)
1516
# we would need to avoid loading the same tests multiple times

Lib/unittest/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from . import loader, runner
88

9+
__unittest = True
10+
911

1012
USAGE_AS_MAIN = """\
1113
Usage: %(progName)s [options] [tests]

Lib/unittest/result.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from . import util
66

7+
__unittest = True
8+
79

810
class TestResult(object):
911
"""Holder for test result information.
@@ -98,11 +100,7 @@ def _exc_info_to_string(self, err, test):
98100
return ''.join(traceback.format_exception(exctype, value, tb))
99101

100102
def _is_relevant_tb_level(self, tb):
101-
globs = tb.tb_frame.f_globals
102-
is_relevant = '__name__' in globs and \
103-
globs["__name__"].startswith("unittest")
104-
del globs
105-
return is_relevant
103+
return '__unittest' in tb.tb_frame.f_globals
106104

107105
def _count_relevant_tb_levels(self, tb):
108106
length = 0

Lib/unittest/runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from . import result
77

8+
__unittest = True
9+
810

911
class _WritelnDecorator(object):
1012
"""Used to decorate file-like objects with a handy 'writeln' method"""

Lib/unittest/suite.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from . import case
66
from . import util
77

8+
__unittest = True
9+
810

911
class BaseTestSuite(object):
1012
"""A simple test suite that doesn't provide class or module shared fixtures.

Lib/unittest/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Various utility functions."""
22

3+
__unittest = True
4+
5+
36
def safe_repr(obj):
47
try:
58
return repr(obj)

0 commit comments

Comments
 (0)