mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
[3.10] bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005) (GH-28027)
(cherry picked from commit 2a8127cafe
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
c081649e6d
commit
462c1f0403
35 changed files with 139 additions and 13 deletions
|
@ -5,6 +5,7 @@ from collections import UserString as ustr
|
|||
from collections.abc import Set, MutableSet
|
||||
import gc
|
||||
import contextlib
|
||||
from test import support
|
||||
|
||||
|
||||
class Foo:
|
||||
|
@ -48,6 +49,7 @@ class TestWeakSet(unittest.TestCase):
|
|||
self.assertEqual(len(self.s), len(self.d))
|
||||
self.assertEqual(len(self.fs), 1)
|
||||
del self.obj
|
||||
support.gc_collect() # For PyPy or other GCs.
|
||||
self.assertEqual(len(self.fs), 0)
|
||||
|
||||
def test_contains(self):
|
||||
|
@ -57,6 +59,7 @@ class TestWeakSet(unittest.TestCase):
|
|||
self.assertNotIn(1, self.s)
|
||||
self.assertIn(self.obj, self.fs)
|
||||
del self.obj
|
||||
support.gc_collect() # For PyPy or other GCs.
|
||||
self.assertNotIn(ustr('F'), self.fs)
|
||||
|
||||
def test_union(self):
|
||||
|
@ -215,6 +218,7 @@ class TestWeakSet(unittest.TestCase):
|
|||
self.assertEqual(self.s, dup)
|
||||
self.assertRaises(TypeError, self.s.add, [])
|
||||
self.fs.add(Foo())
|
||||
support.gc_collect() # For PyPy or other GCs.
|
||||
self.assertTrue(len(self.fs) == 1)
|
||||
self.fs.add(self.obj)
|
||||
self.assertTrue(len(self.fs) == 1)
|
||||
|
@ -406,6 +410,7 @@ class TestWeakSet(unittest.TestCase):
|
|||
n1 = len(s)
|
||||
del it
|
||||
gc.collect()
|
||||
gc.collect() # For PyPy or other GCs.
|
||||
n2 = len(s)
|
||||
# one item may be kept alive inside the iterator
|
||||
self.assertIn(n1, (0, 1))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue