mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
4709ec0686
commit
31f5929c1e
15 changed files with 283 additions and 221 deletions
|
@ -251,6 +251,7 @@ class TraceTestCase(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.using_gc = gc.isenabled()
|
||||
gc.disable()
|
||||
self.addCleanup(sys.settrace, sys.gettrace())
|
||||
|
||||
def tearDown(self):
|
||||
if self.using_gc:
|
||||
|
@ -389,6 +390,9 @@ class TraceTestCase(unittest.TestCase):
|
|||
|
||||
|
||||
class RaisingTraceFuncTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.addCleanup(sys.settrace, sys.gettrace())
|
||||
|
||||
def trace(self, frame, event, arg):
|
||||
"""A trace function that raises an exception in response to a
|
||||
specific trace event."""
|
||||
|
@ -688,6 +692,10 @@ def no_jump_without_trace_function():
|
|||
|
||||
|
||||
class JumpTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.addCleanup(sys.settrace, sys.gettrace())
|
||||
sys.settrace(None)
|
||||
|
||||
def compare_jump_output(self, expected, received):
|
||||
if received != expected:
|
||||
self.fail( "Outputs don't match:\n" +
|
||||
|
@ -739,6 +747,8 @@ class JumpTestCase(unittest.TestCase):
|
|||
def test_18_no_jump_to_non_integers(self):
|
||||
self.run_test(no_jump_to_non_integers)
|
||||
def test_19_no_jump_without_trace_function(self):
|
||||
# Must set sys.settrace(None) in setUp(), else condition is not
|
||||
# triggered.
|
||||
no_jump_without_trace_function()
|
||||
|
||||
def test_20_large_function(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue