mirror of
https://github.com/python/cpython.git
synced 2025-11-07 17:12:03 +00:00
[3.9] bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005). (GH-28028)
(cherry picked from commit 2a8127cafe)
This commit is contained in:
parent
dab74d68e3
commit
330aabbbbe
36 changed files with 143 additions and 15 deletions
|
|
@ -5,6 +5,7 @@
|
|||
from collections.abc import Set, MutableSet
|
||||
import gc
|
||||
import contextlib
|
||||
from test import support
|
||||
|
||||
|
||||
class Foo:
|
||||
|
|
@ -48,6 +49,7 @@ def test_len(self):
|
|||
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 @@ def test_contains(self):
|
|||
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 @@ def test_add(self):
|
|||
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 @@ def test_len_cycles(self):
|
|||
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