Re: [Python-Dev] [Python-checkins] cpython: Issue #11798: fix tests for regrtest -R :

On Sat, Aug 31, 2013 at 9:58 PM, andrew.svetlov <python-checkins@python.org>wrote:
http://hg.python.org/cpython/rev/39781c3737f8 changeset: 85490:39781c3737f8 user: Andrew Svetlov <andrew.svetlov@gmail.com> date: Sun Sep 01 07:58:41 2013 +0300 summary: Issue #11798: fix tests for regrtest -R :
files: Lib/test/regrtest.py | 5 +++++ Lib/unittest/suite.py | 8 ++++++-- Lib/unittest/test/test_suite.py | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-)
Hi Andrew, It would help if you could add more details into the commit message. This would make both post-commit reviews and future code archeology simpler. Eli
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -496,6 +496,8 @@
if ns.slaveargs is not None: args, kwargs = json.loads(ns.slaveargs) + if kwargs.get('huntrleaks'): + unittest.BaseTestSuite._cleanup = False try: result = runtest(*args, **kwargs) except KeyboardInterrupt: @@ -528,6 +530,9 @@ #gc.set_debug(gc.DEBUG_SAVEALL) found_garbage = []
+ if ns.huntrleaks: + unittest.BaseTestSuite._cleanup = False + if ns.single: filename = os.path.join(TEMPDIR, 'pynexttest') try: diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -16,6 +16,8 @@ class BaseTestSuite(object): """A simple test suite that doesn't provide class or module shared fixtures. """ + _cleanup = True + def __init__(self, tests=()): self._tests = [] self.addTests(tests) @@ -61,7 +63,8 @@ if result.shouldStop: break test(result) - self._removeTestAtIndex(index) + if self._cleanup: + self._removeTestAtIndex(index) return result
def _removeTestAtIndex(self, index): @@ -115,7 +118,8 @@ else: test.debug()
- self._removeTestAtIndex(index) + if self._cleanup: + self._removeTestAtIndex(index)
if topLevel: self._tearDownPreviousClass(None, result) diff --git a/Lib/unittest/test/test_suite.py b/Lib/unittest/test/test_suite.py --- a/Lib/unittest/test/test_suite.py +++ b/Lib/unittest/test/test_suite.py @@ -303,6 +303,9 @@ suite.run(unittest.TestResult())
def test_remove_test_at_index(self): + if not unittest.BaseTestSuite._cleanup: + raise unittest.SkipTest("Suite cleanup is disabled") + suite = unittest.TestSuite()
suite._tests = [1, 2, 3] @@ -311,6 +314,9 @@ self.assertEqual([1, None, 3], suite._tests)
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._tests = None
@@ -318,6 +324,8 @@ suite._removeTestAtIndex(2)
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): def test_nothing(self):
-- Repository URL: http://hg.python.org/cpython
_______________________________________________ Python-checkins mailing list Python-checkins@python.org http://mail.python.org/mailman/listinfo/python-checkins

regrtest -R runs test suites several times. That's why test cleanup should be disabled for this case. Details discussed in issue. I'll do more expressive commit messages next time. Thanks. On Mon, Sep 2, 2013 at 1:58 AM, Eli Bendersky <eliben@gmail.com> wrote:
On Sat, Aug 31, 2013 at 9:58 PM, andrew.svetlov <python-checkins@python.org> wrote:
http://hg.python.org/cpython/rev/39781c3737f8 changeset: 85490:39781c3737f8 user: Andrew Svetlov <andrew.svetlov@gmail.com> date: Sun Sep 01 07:58:41 2013 +0300 summary: Issue #11798: fix tests for regrtest -R :
files: Lib/test/regrtest.py | 5 +++++ Lib/unittest/suite.py | 8 ++++++-- Lib/unittest/test/test_suite.py | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-)
Hi Andrew,
It would help if you could add more details into the commit message. This would make both post-commit reviews and future code archeology simpler.
Eli
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -496,6 +496,8 @@
if ns.slaveargs is not None: args, kwargs = json.loads(ns.slaveargs) + if kwargs.get('huntrleaks'): + unittest.BaseTestSuite._cleanup = False try: result = runtest(*args, **kwargs) except KeyboardInterrupt: @@ -528,6 +530,9 @@ #gc.set_debug(gc.DEBUG_SAVEALL) found_garbage = []
+ if ns.huntrleaks: + unittest.BaseTestSuite._cleanup = False + if ns.single: filename = os.path.join(TEMPDIR, 'pynexttest') try: diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -16,6 +16,8 @@ class BaseTestSuite(object): """A simple test suite that doesn't provide class or module shared fixtures. """ + _cleanup = True + def __init__(self, tests=()): self._tests = [] self.addTests(tests) @@ -61,7 +63,8 @@ if result.shouldStop: break test(result) - self._removeTestAtIndex(index) + if self._cleanup: + self._removeTestAtIndex(index) return result
def _removeTestAtIndex(self, index): @@ -115,7 +118,8 @@ else: test.debug()
- self._removeTestAtIndex(index) + if self._cleanup: + self._removeTestAtIndex(index)
if topLevel: self._tearDownPreviousClass(None, result) diff --git a/Lib/unittest/test/test_suite.py b/Lib/unittest/test/test_suite.py --- a/Lib/unittest/test/test_suite.py +++ b/Lib/unittest/test/test_suite.py @@ -303,6 +303,9 @@ suite.run(unittest.TestResult())
def test_remove_test_at_index(self): + if not unittest.BaseTestSuite._cleanup: + raise unittest.SkipTest("Suite cleanup is disabled") + suite = unittest.TestSuite()
suite._tests = [1, 2, 3] @@ -311,6 +314,9 @@ self.assertEqual([1, None, 3], suite._tests)
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._tests = None
@@ -318,6 +324,8 @@ suite._removeTestAtIndex(2)
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): def test_nothing(self):
-- Repository URL: http://hg.python.org/cpython
_______________________________________________ Python-checkins mailing list Python-checkins@python.org http://mail.python.org/mailman/listinfo/python-checkins
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/andrew.svetlov%40gmail.com
-- Thanks, Andrew Svetlov
participants (2)
-
Andrew Svetlov
-
Eli Bendersky