Issue 7815. __unittest in module globals trims frames from reported stacktraces in unittest.

This commit is contained in:
Michael Foord 2010-03-22 00:06:30 +00:00
parent bb9d726357
commit b1aa30f94d
10 changed files with 32 additions and 5 deletions

View file

@ -64,3 +64,5 @@ from .runner import TextTestRunner, TextTestResult
# deprecated
_TextTestResult = TextTestResult
__unittest = True

View file

@ -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)

View file

@ -12,6 +12,9 @@ from .util import (
strclass, safe_repr, sorted_list_difference, unorderable_list_difference
)
__unittest = True
class SkipTest(Exception):
"""
Raise this exception in a test to skip it.

View file

@ -10,6 +10,8 @@ from fnmatch import fnmatch
from . import case, suite
__unittest = True
def _CmpToKey(mycmp):
'Convert a cmp= function into a key= function'

View file

@ -6,6 +6,8 @@ import types
from . import loader, runner
__unittest = True
USAGE_AS_MAIN = """\
Usage: %(progName)s [options] [tests]

View file

@ -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

View file

@ -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"""

View file

@ -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.

View file

@ -1,5 +1,8 @@
"""Various utility functions."""
__unittest = True
def safe_repr(obj):
try:
return repr(obj)