diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-05-11 21:10:52 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-05-11 21:10:52 (GMT) |
commit | 2943cdb5eb7f342a4cdaec59893825de172eedc6 (patch) | |
tree | bf48aa0ef0277778d764115a4ae1979a3348888f /Lib/test/test_scope.py | |
parent | 4c8bf6b73293a1ba90b7ff3b4b95468a889357b1 (diff) | |
download | cpython-2943cdb5eb7f342a4cdaec59893825de172eedc6.zip cpython-2943cdb5eb7f342a4cdaec59893825de172eedc6.tar.gz cpython-2943cdb5eb7f342a4cdaec59893825de172eedc6.tar.bz2 |
simplify #17947 test with weakrefs
Diffstat (limited to 'Lib/test/test_scope.py')
-rw-r--r-- | Lib/test/test_scope.py | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 1c06224..70065f9 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -1,5 +1,7 @@ import gc import unittest +import weakref + from test.support import check_syntax_error, cpython_only, run_unittest @@ -740,16 +742,7 @@ class ScopeTests(unittest.TestCase): # (though it will be cleared when the frame is collected). # Without the lambda, setting self to None is enough to break # the cycle. - logs = [] - class Canary: - def __del__(self): - logs.append('canary') - class Base: - def dig(self): - pass - class Tester(Base): - def __init__(self): - self.canary = Canary() + class Tester: def dig(self): if 0: lambda: self @@ -757,14 +750,12 @@ class ScopeTests(unittest.TestCase): 1/0 except Exception as exc: self.exc = exc - super().dig() self = None # Break the cycle tester = Tester() tester.dig() + ref = weakref.ref(tester) del tester - logs.append('collect') - gc.collect() - self.assertEqual(logs, ['canary', 'collect']) + self.assertIsNone(ref()) def test_main(): |