diff options
author | Brett Cannon <bcannon@gmail.com> | 2011-02-21 19:29:56 +0000 |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2011-02-21 19:29:56 +0000 |
commit | 1dac76d094f0665b832f08299c7fd4a4b5e6e708 (patch) | |
tree | 035cb43b6bcbe471125cbc6faa221b19600cef07 /Lib/test/support.py | |
parent | 23ea7691fb00ce907f825f9c7e6d0df9fd8fc825 (diff) | |
download | cpython-1dac76d094f0665b832f08299c7fd4a4b5e6e708.tar.gz |
Issue #10990: Prevent tests from clobbering a set trace function.
Many tests simply didn't care if they unset a pre-existing trace function. This
made test coverage impossible. This patch fixes various tests to put back any
pre-existing trace function. It also introduces test.support.no_tracing as a
decorator which will temporarily unset the trace function for tests which
simply fail otherwise.
Thanks to Kristian Vlaardingerbroek for helping to find the cause of various
trace function unsets.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r-- | Lib/test/support.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index ea5b9cbda4..f037a7aed8 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -1108,6 +1108,21 @@ def check_impl_detail(**guards): return guards.get(platform.python_implementation().lower(), default) +def no_tracing(func): + """Decorator to temporarily turn off tracing for the duration of a test.""" + if not hasattr(sys, 'gettrace'): + return func + else: + @functools.wraps(func) + def wrapper(*args, **kwargs): + original_trace = sys.gettrace() + try: + sys.settrace(None) + return func(*args, **kwargs) + finally: + sys.settrace(original_trace) + return wrapper + def _run_suite(suite): """Run tests from a unittest.TestSuite-derived class.""" |