summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_trace.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2011-02-21 19:29:56 (GMT)
committerBrett Cannon <bcannon@gmail.com>2011-02-21 19:29:56 (GMT)
commit31f5929c1e28adcaa1fdb302da366f3c7a92a98a (patch)
tree5035df0c8c20111fb27a4940e38401f244bc9854 /Lib/test/test_trace.py
parent4709ec0686ba85466a293b85a243979882696240 (diff)
downloadcpython-31f5929c1e28adcaa1fdb302da366f3c7a92a98a.zip
cpython-31f5929c1e28adcaa1fdb302da366f3c7a92a98a.tar.gz
cpython-31f5929c1e28adcaa1fdb302da366f3c7a92a98a.tar.bz2
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/test_trace.py')
-rw-r--r--Lib/test/test_trace.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 93df84f..9266280 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -102,6 +102,7 @@ class TracedClass(object):
class TestLineCounts(unittest.TestCase):
"""White-box testing of line-counting, via runfunc"""
def setUp(self):
+ self.addCleanup(sys.settrace, sys.gettrace())
self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
self.my_py_filename = fix_ext_py(__file__)
@@ -192,6 +193,7 @@ class TestRunExecCounts(unittest.TestCase):
"""A simple sanity test of line-counting, via runctx (exec)"""
def setUp(self):
self.my_py_filename = fix_ext_py(__file__)
+ self.addCleanup(sys.settrace, sys.gettrace())
def test_exec_counts(self):
self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
@@ -218,6 +220,7 @@ class TestRunExecCounts(unittest.TestCase):
class TestFuncs(unittest.TestCase):
"""White-box testing of funcs tracing"""
def setUp(self):
+ self.addCleanup(sys.settrace, sys.gettrace())
self.tracer = Trace(count=0, trace=0, countfuncs=1)
self.filemod = my_file_and_modname()
@@ -257,6 +260,7 @@ class TestFuncs(unittest.TestCase):
class TestCallers(unittest.TestCase):
"""White-box testing of callers tracing"""
def setUp(self):
+ self.addCleanup(sys.settrace, sys.gettrace())
self.tracer = Trace(count=0, trace=0, countcallers=1)
self.filemod = my_file_and_modname()
@@ -280,6 +284,9 @@ class TestCallers(unittest.TestCase):
# Created separately for issue #3821
class TestCoverage(unittest.TestCase):
+ def setUp(self):
+ self.addCleanup(sys.settrace, sys.gettrace())
+
def tearDown(self):
rmtree(TESTFN)
unlink(TESTFN)