Issue #11798: fix tests for regrtest -R :

This commit is contained in:
Andrew Svetlov 2013-09-01 07:58:41 +03:00
parent 59360aadd3
commit 8913a6c83d
3 changed files with 19 additions and 2 deletions

View File

@ -496,6 +496,8 @@ def main(tests=None, **kwargs):
if ns.slaveargs is not None: if ns.slaveargs is not None:
args, kwargs = json.loads(ns.slaveargs) args, kwargs = json.loads(ns.slaveargs)
if kwargs.get('huntrleaks'):
unittest.BaseTestSuite._cleanup = False
try: try:
result = runtest(*args, **kwargs) result = runtest(*args, **kwargs)
except KeyboardInterrupt: except KeyboardInterrupt:
@ -528,6 +530,9 @@ def main(tests=None, **kwargs):
#gc.set_debug(gc.DEBUG_SAVEALL) #gc.set_debug(gc.DEBUG_SAVEALL)
found_garbage = [] found_garbage = []
if ns.huntrleaks:
unittest.BaseTestSuite._cleanup = False
if ns.single: if ns.single:
filename = os.path.join(TEMPDIR, 'pynexttest') filename = os.path.join(TEMPDIR, 'pynexttest')
try: try:

View File

@ -16,6 +16,8 @@ def _call_if_exists(parent, attr):
class BaseTestSuite(object): class BaseTestSuite(object):
"""A simple test suite that doesn't provide class or module shared fixtures. """A simple test suite that doesn't provide class or module shared fixtures.
""" """
_cleanup = True
def __init__(self, tests=()): def __init__(self, tests=()):
self._tests = [] self._tests = []
self.addTests(tests) self.addTests(tests)
@ -61,6 +63,7 @@ class BaseTestSuite(object):
if result.shouldStop: if result.shouldStop:
break break
test(result) test(result)
if self._cleanup:
self._removeTestAtIndex(index) self._removeTestAtIndex(index)
return result return result
@ -115,6 +118,7 @@ class TestSuite(BaseTestSuite):
else: else:
test.debug() test.debug()
if self._cleanup:
self._removeTestAtIndex(index) self._removeTestAtIndex(index)
if topLevel: if topLevel:

View File

@ -303,6 +303,9 @@ class Test_TestSuite(unittest.TestCase, TestEquality):
suite.run(unittest.TestResult()) suite.run(unittest.TestResult())
def test_remove_test_at_index(self): def test_remove_test_at_index(self):
if not unittest.BaseTestSuite._cleanup:
raise unittest.SkipTest("Suite cleanup is disabled")
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite._tests = [1, 2, 3] suite._tests = [1, 2, 3]
@ -311,6 +314,9 @@ class Test_TestSuite(unittest.TestCase, TestEquality):
self.assertEqual([1, None, 3], suite._tests) self.assertEqual([1, None, 3], suite._tests)
def test_remove_test_at_index_not_indexable(self): def test_remove_test_at_index_not_indexable(self):
if not unittest.BaseTestSuite._cleanup:
raise unittest.SkipTest("Suite cleanup is disabled")
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite._tests = None suite._tests = None
@ -318,6 +324,8 @@ class Test_TestSuite(unittest.TestCase, TestEquality):
suite._removeTestAtIndex(2) suite._removeTestAtIndex(2)
def assert_garbage_collect_test_after_run(self, TestSuiteClass): def assert_garbage_collect_test_after_run(self, TestSuiteClass):
if not unittest.BaseTestSuite._cleanup:
raise unittest.SkipTest("Suite cleanup is disabled")
class Foo(unittest.TestCase): class Foo(unittest.TestCase):
def test_nothing(self): def test_nothing(self):