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:
Brett Cannon 2011-02-21 19:29:56 +00:00
parent 4709ec0686
commit 31f5929c1e
15 changed files with 283 additions and 221 deletions

View file

@ -7,7 +7,7 @@
import weakref
from test.support import (TESTFN, unlink, run_unittest, captured_output,
gc_collect, cpython_only)
gc_collect, cpython_only, no_tracing)
# XXX This is not really enough, each *operation* should be tested!
@ -388,6 +388,7 @@ def __init__(self, fancy_arg):
x = DerivedException(fancy_arg=42)
self.assertEqual(x.fancy_arg, 42)
@no_tracing
def testInfiniteRecursion(self):
def f():
return f()
@ -631,6 +632,7 @@ def testUnicodeChangeAttributes(self):
u.start = 1000
self.assertEqual(str(u), "can't translate characters in position 1000-4: 965230951443685724997")
@no_tracing
def test_badisinstance(self):
# Bug #2542: if issubclass(e, MyException) raises an exception,
# it should be ignored
@ -741,6 +743,7 @@ def inner():
self.fail("MemoryError not raised")
self.assertEqual(wr(), None)
@no_tracing
def test_recursion_error_cleanup(self):
# Same test as above, but with "recursion exceeded" errors
class C: