44
55import pytest
66
7- import env # noqa: F401
7+ import env
88from pybind11_tests import ConstructorStats
99from pybind11_tests import methods_and_attributes as m
1010
1919)
2020
2121
22- @pytest .mark .skipif ("env.GRAALPY" , reason = "Cannot reliably trigger GC" )
2322def test_methods_and_attributes ():
2423 instance1 = m .ExampleMandA ()
2524 instance2 = m .ExampleMandA (32 )
@@ -69,16 +68,17 @@ def test_methods_and_attributes():
6968 instance1 .value = 100
7069 assert str (instance1 ) == "ExampleMandA[value=100]"
7170
72- cstats = ConstructorStats .get (m .ExampleMandA )
73- assert cstats .alive () == 2
74- del instance1 , instance2
75- assert cstats .alive () == 0
76- assert cstats .values () == ["32" ]
77- assert cstats .default_constructions == 1
78- assert cstats .copy_constructions == 2
79- assert cstats .move_constructions >= 2
80- assert cstats .copy_assignments == 0
81- assert cstats .move_assignments == 0
71+ if not env .GRAALPY :
72+ cstats = ConstructorStats .get (m .ExampleMandA )
73+ assert cstats .alive () == 2
74+ del instance1 , instance2
75+ assert cstats .alive () == 0
76+ assert cstats .values () == ["32" ]
77+ assert cstats .default_constructions == 1
78+ assert cstats .copy_constructions == 2
79+ assert cstats .move_constructions >= 2
80+ assert cstats .copy_assignments == 0
81+ assert cstats .move_assignments == 0
8282
8383
8484def test_copy_method ():
@@ -296,7 +296,6 @@ def test_property_rvalue_policy():
296296
297297# https://foss.heptapod.net/pypy/pypy/-/issues/2447
298298@pytest .mark .xfail ("env.PYPY" )
299- @pytest .mark .skipif ("env.GRAALPY" , reason = "Cannot reliably trigger GC" )
300299def test_dynamic_attributes ():
301300 instance = m .DynamicClass ()
302301 assert not hasattr (instance , "foo" )
@@ -314,14 +313,17 @@ def test_dynamic_attributes():
314313 assert not hasattr (instance , "foo" )
315314 assert hasattr (instance , "bar" )
316315
317- with pytest .raises (TypeError ) as excinfo :
318- instance .__dict__ = []
319- assert str (excinfo .value ) == "__dict__ must be set to a dictionary, not a 'list'"
316+ if not env .GRAALPY :
317+ with pytest .raises (TypeError ) as excinfo :
318+ instance .__dict__ = []
319+ assert (
320+ str (excinfo .value ) == "__dict__ must be set to a dictionary, not a 'list'"
321+ )
320322
321- cstats = ConstructorStats .get (m .DynamicClass )
322- assert cstats .alive () == 1
323- del instance
324- assert cstats .alive () == 0
323+ cstats = ConstructorStats .get (m .DynamicClass )
324+ assert cstats .alive () == 1
325+ del instance
326+ assert cstats .alive () == 0
325327
326328 # Derived classes should work as well
327329 class PythonDerivedDynamicClass (m .DynamicClass ):
@@ -332,9 +334,10 @@ class PythonDerivedDynamicClass(m.DynamicClass):
332334 derived .foobar = 100
333335 assert derived .foobar == 100
334336
335- assert cstats .alive () == 1
336- del derived
337- assert cstats .alive () == 0
337+ if not env .GRAALPY :
338+ assert cstats .alive () == 1
339+ del derived
340+ assert cstats .alive () == 0
338341
339342
340343# https://foss.heptapod.net/pypy/pypy/-/issues/2447
0 commit comments