diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-01-14 12:06:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-14 12:06:45 (GMT) |
commit | a2ec3f07f7f028ff6229d6be2a7cfbda1f4efaeb (patch) | |
tree | 2ca30015db1da7016d3f0eff8e253dcfc298452a /Lib/test/test_gc.py | |
parent | 1d1b97ae643dd8b22d87785ed7bd2599c6c8dc8d (diff) | |
download | cpython-a2ec3f07f7f028ff6229d6be2a7cfbda1f4efaeb.zip cpython-a2ec3f07f7f028ff6229d6be2a7cfbda1f4efaeb.tar.gz cpython-a2ec3f07f7f028ff6229d6be2a7cfbda1f4efaeb.tar.bz2 |
bpo-39322: Add gc.is_finalized to check if an object has been finalised by the gc (GH-17989)
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r-- | Lib/test/test_gc.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index c0d4a75..18f8d10 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -586,6 +586,24 @@ class GCTests(unittest.TestCase): self.assertFalse(gc.is_tracked(UserFloatSlots())) self.assertFalse(gc.is_tracked(UserIntSlots())) + def test_is_finalized(self): + # Objects not tracked by the always gc return false + self.assertFalse(gc.is_finalized(3)) + + storage = [] + class Lazarus: + def __del__(self): + storage.append(self) + + lazarus = Lazarus() + self.assertFalse(gc.is_finalized(lazarus)) + + del lazarus + gc.collect() + + lazarus = storage.pop() + self.assertTrue(gc.is_finalized(lazarus)) + def test_bug1055820b(self): # Corresponds to temp2b.py in the bug report. |