Commits

Benjamin Peterson committed 1b59539

simplify #17947 test with weakrefs

  • Participants
  • Parent commits 0dd04c3

Comments (0)

Files changed (1)

Lib/test/test_scope.py

 import gc
 import unittest
+import weakref
+
 from test.support import check_syntax_error, cpython_only, run_unittest
 
 
         # (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
                     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():