From: Serhiy Storchaka Date: Sun, 12 Jun 2016 12:45:14 +0000 (+0300) Subject: Issue #25455: Clean up reference loops created in tests for recursive X-Git-Tag: v2.7.13rc1~292 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50c7e056595aadc25c5aa483f94384c30584a233;p=thirdparty%2FPython%2Fcpython.git Issue #25455: Clean up reference loops created in tests for recursive functools.partial objects. --- diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 8a45e6852313..62d60296bcb5 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -239,21 +239,36 @@ class TestPartial(unittest.TestCase): def test_recursive_pickle(self): f = self.partial(capture) f.__setstate__((f, (), {}, {})) - for proto in range(pickle.HIGHEST_PROTOCOL + 1): - with self.assertRaises(RuntimeError): - pickle.dumps(f, proto) + try: + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + with self.assertRaises(RuntimeError): + pickle.dumps(f, proto) + finally: + f.__setstate__((capture, (), {}, {})) f = self.partial(capture) f.__setstate__((capture, (f,), {}, {})) - for proto in range(pickle.HIGHEST_PROTOCOL + 1): - f_copy = pickle.loads(pickle.dumps(f, proto)) - self.assertIs(f_copy.args[0], f_copy) + try: + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + f_copy = pickle.loads(pickle.dumps(f, proto)) + try: + self.assertIs(f_copy.args[0], f_copy) + finally: + f_copy.__setstate__((capture, (), {}, {})) + finally: + f.__setstate__((capture, (), {}, {})) f = self.partial(capture) f.__setstate__((capture, (), {'a': f}, {})) - for proto in range(pickle.HIGHEST_PROTOCOL + 1): - f_copy = pickle.loads(pickle.dumps(f, proto)) - self.assertIs(f_copy.keywords['a'], f_copy) + try: + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + f_copy = pickle.loads(pickle.dumps(f, proto)) + try: + self.assertIs(f_copy.keywords['a'], f_copy) + finally: + f_copy.__setstate__((capture, (), {}, {})) + finally: + f.__setstate__((capture, (), {}, {})) # Issue 6083: Reference counting bug def test_setstate_refcount(self):