mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
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. ........
This commit is contained in:
parent
a6884fc0fd
commit
dccc1fcfaf
10 changed files with 30 additions and 5 deletions
|
|
@ -2096,6 +2096,16 @@ class Test_TestResult(TestCase):
|
||||||
'Tests getDescription() for a method with a longer '
|
'Tests getDescription() for a method with a longer '
|
||||||
'docstring.'))
|
'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__)
|
classDict = dict(unittest.TestResult.__dict__)
|
||||||
for m in ('addSkip', 'addExpectedFailure', 'addUnexpectedSuccess',
|
for m in ('addSkip', 'addExpectedFailure', 'addUnexpectedSuccess',
|
||||||
'__init__'):
|
'__init__'):
|
||||||
|
|
|
||||||
|
|
@ -64,3 +64,5 @@ from .runner import TextTestRunner, TextTestResult
|
||||||
|
|
||||||
# deprecated
|
# deprecated
|
||||||
_TextTestResult = TextTestResult
|
_TextTestResult = TextTestResult
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,8 @@ import sys
|
||||||
if sys.argv[0].endswith("__main__.py"):
|
if sys.argv[0].endswith("__main__.py"):
|
||||||
sys.argv[0] = "unittest"
|
sys.argv[0] = "unittest"
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
||||||
|
|
||||||
from .main import main
|
from .main import main
|
||||||
main(module=None)
|
main(module=None)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ from . import result
|
||||||
from .util import (strclass, safe_repr, sorted_list_difference,
|
from .util import (strclass, safe_repr, sorted_list_difference,
|
||||||
unorderable_list_difference)
|
unorderable_list_difference)
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
||||||
|
|
||||||
class SkipTest(Exception):
|
class SkipTest(Exception):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from fnmatch import fnmatch
|
||||||
|
|
||||||
from . import case, suite, util
|
from . import case, suite, util
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
||||||
# what about .pyc or .pyo (etc)
|
# what about .pyc or .pyo (etc)
|
||||||
# we would need to avoid loading the same tests multiple times
|
# we would need to avoid loading the same tests multiple times
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import types
|
||||||
|
|
||||||
from . import loader, runner
|
from . import loader, runner
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
||||||
|
|
||||||
USAGE_AS_MAIN = """\
|
USAGE_AS_MAIN = """\
|
||||||
Usage: %(progName)s [options] [tests]
|
Usage: %(progName)s [options] [tests]
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import traceback
|
||||||
|
|
||||||
from . import util
|
from . import util
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
||||||
|
|
||||||
class TestResult(object):
|
class TestResult(object):
|
||||||
"""Holder for test result information.
|
"""Holder for test result information.
|
||||||
|
|
@ -98,11 +100,7 @@ class TestResult(object):
|
||||||
return ''.join(traceback.format_exception(exctype, value, tb))
|
return ''.join(traceback.format_exception(exctype, value, tb))
|
||||||
|
|
||||||
def _is_relevant_tb_level(self, tb):
|
def _is_relevant_tb_level(self, tb):
|
||||||
globs = tb.tb_frame.f_globals
|
return '__unittest' in tb.tb_frame.f_globals
|
||||||
is_relevant = '__name__' in globs and \
|
|
||||||
globs["__name__"].startswith("unittest")
|
|
||||||
del globs
|
|
||||||
return is_relevant
|
|
||||||
|
|
||||||
def _count_relevant_tb_levels(self, tb):
|
def _count_relevant_tb_levels(self, tb):
|
||||||
length = 0
|
length = 0
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import time
|
||||||
|
|
||||||
from . import result
|
from . import result
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
||||||
|
|
||||||
class _WritelnDecorator(object):
|
class _WritelnDecorator(object):
|
||||||
"""Used to decorate file-like objects with a handy 'writeln' method"""
|
"""Used to decorate file-like objects with a handy 'writeln' method"""
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import sys
|
||||||
from . import case
|
from . import case
|
||||||
from . import util
|
from . import util
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
||||||
|
|
||||||
class BaseTestSuite(object):
|
class BaseTestSuite(object):
|
||||||
"""A simple test suite that doesn't provide class or module shared fixtures.
|
"""A simple test suite that doesn't provide class or module shared fixtures.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
"""Various utility functions."""
|
"""Various utility functions."""
|
||||||
|
|
||||||
|
__unittest = True
|
||||||
|
|
||||||
|
|
||||||
def safe_repr(obj):
|
def safe_repr(obj):
|
||||||
try:
|
try:
|
||||||
return repr(obj)
|
return repr(obj)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue