11from __future__ import annotations
22
3- import gc
43import sys
54
65import pytest
2019)
2120
2221
23- def gc_collect (repeat = 5 ):
24- """Collect garbage multiple times to ensure that objects are actually deleted."""
25- for _ in range (repeat ):
26- gc .collect ()
27-
28-
2922def test_self_only_pos_only ():
3023 assert (
3124 m .ExampleMandA .__str__ .__doc__
@@ -316,7 +309,7 @@ def test_property_rvalue_policy():
316309 sys .version_info == (3 , 14 , 0 , "beta" , 1 )
317310 or sys .version_info == (3 , 14 , 0 , "beta" , 2 ),
318311 reason = "3.14.0b1/2 bug: https://github.com/python/cpython/issues/133912" ,
319- strict = False ,
312+ strict = True ,
320313)
321314def test_dynamic_attributes ():
322315 instance = m .DynamicClass ()
@@ -344,32 +337,24 @@ def test_dynamic_attributes():
344337 cstats = ConstructorStats .get (m .DynamicClass )
345338 assert cstats .alive () == 1
346339 del instance
347- gc_collect (repeat = 10 )
348340 assert cstats .alive () == 0
349341
350342 # Derived classes should work as well
351343 class PythonDerivedDynamicClass (m .DynamicClass ):
352344 pass
353345
354- for cls in ( m .CppDerivedDynamicClass , PythonDerivedDynamicClass ) :
346+ for cls in m .CppDerivedDynamicClass , PythonDerivedDynamicClass :
355347 derived = cls ()
356348 derived .foobar = 100
357349 assert derived .foobar == 100
358350
359351 assert cstats .alive () == 1
360352 del derived
361- gc_collect (repeat = 10 )
362353 assert cstats .alive () == 0
363354
364355
365356# https://foss.heptapod.net/pypy/pypy/-/issues/2447
366357@pytest .mark .xfail ("env.PYPY" )
367- @pytest .mark .xfail (
368- sys .version_info == (3 , 14 , 0 , "beta" , 1 )
369- or sys .version_info == (3 , 14 , 0 , "beta" , 2 ),
370- reason = "3.14.0b1/2 bug: https://github.com/python/cpython/issues/133912" ,
371- strict = False ,
372- )
373358@pytest .mark .skipif ("env.GRAALPY" , reason = "Cannot reliably trigger GC" )
374359def test_cyclic_gc ():
375360 # One object references itself
@@ -379,7 +364,6 @@ def test_cyclic_gc():
379364 cstats = ConstructorStats .get (m .DynamicClass )
380365 assert cstats .alive () == 1
381366 del instance
382- gc_collect (repeat = 10 )
383367 assert cstats .alive () == 0
384368
385369 # Two object reference each other
@@ -390,7 +374,6 @@ def test_cyclic_gc():
390374
391375 assert cstats .alive () == 2
392376 del i1 , i2
393- gc_collect (repeat = 10 )
394377 assert cstats .alive () == 0
395378
396379
0 commit comments