diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2013-08-28 18:28:38 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2013-08-28 18:28:38 (GMT) |
commit | eb9736845182a732b2fcfb32730984d7c6fff7f3 (patch) | |
tree | 8f613d582fd60002494fa0f8e4173d730c444abc /Lib/unittest/suite.py | |
parent | 6a53af893ad2708af8dda71515254abd7118d7de (diff) | |
download | cpython-eb9736845182a732b2fcfb32730984d7c6fff7f3.zip cpython-eb9736845182a732b2fcfb32730984d7c6fff7f3.tar.gz cpython-eb9736845182a732b2fcfb32730984d7c6fff7f3.tar.bz2 |
Issue #11798: TestSuite now drops references to own tests after execution.
Diffstat (limited to 'Lib/unittest/suite.py')
-rw-r--r-- | Lib/unittest/suite.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py index cde5d38..176af57 100644 --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -57,12 +57,21 @@ class BaseTestSuite(object): self.addTest(test) def run(self, result): - for test in self: + for index, test in enumerate(self): if result.shouldStop: break test(result) + self._removeTestAtIndex(index) return result + def _removeTestAtIndex(self, index): + """Stop holding a reference to the TestCase at index.""" + try: + self._tests[index] = None + except TypeError: + # support for suite implementations that have overriden self._test + pass + def __call__(self, *args, **kwds): return self.run(*args, **kwds) @@ -87,7 +96,7 @@ class TestSuite(BaseTestSuite): if getattr(result, '_testRunEntered', False) is False: result._testRunEntered = topLevel = True - for test in self: + for index, test in enumerate(self): if result.shouldStop: break @@ -106,6 +115,8 @@ class TestSuite(BaseTestSuite): else: test.debug() + self._removeTestAtIndex(index) + if topLevel: self._tearDownPreviousClass(None, result) self._handleModuleTearDown(result) |