Skip to content

Commit 9b337ef

Browse files
committed
Try to narrow down skipped tests
1 parent 3cc2fa9 commit 9b337ef

6 files changed

+120
-108
lines changed

Diff for: tests/test_buffers.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def test_format_descriptor_format_buffer_info_equiv(cpp_name, np_dtype):
7070
assert not np_array_is_matching
7171

7272

73-
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
7473
def test_from_python():
7574
with pytest.raises(RuntimeError) as excinfo:
7675
m.Matrix(np.array([1, 2, 3])) # trying to assign a 1D array
@@ -83,23 +82,23 @@ def test_from_python():
8382
for j in range(m4.cols()):
8483
assert m3[i, j] == m4[i, j]
8584

86-
cstats = ConstructorStats.get(m.Matrix)
87-
assert cstats.alive() == 1
88-
del m3, m4
89-
assert cstats.alive() == 0
90-
assert cstats.values() == ["2x3 matrix"]
91-
assert cstats.copy_constructions == 0
92-
# assert cstats.move_constructions >= 0 # Don't invoke any
93-
assert cstats.copy_assignments == 0
94-
assert cstats.move_assignments == 0
85+
if not env.GRAALPY:
86+
cstats = ConstructorStats.get(m.Matrix)
87+
assert cstats.alive() == 1
88+
del m3, m4
89+
assert cstats.alive() == 0
90+
assert cstats.values() == ["2x3 matrix"]
91+
assert cstats.copy_constructions == 0
92+
# assert cstats.move_constructions >= 0 # Don't invoke any
93+
assert cstats.copy_assignments == 0
94+
assert cstats.move_assignments == 0
9595

9696

9797
# https://foss.heptapod.net/pypy/pypy/-/issues/2444
9898
# TODO: fix on recent PyPy
9999
@pytest.mark.xfail(
100100
env.PYPY, reason="PyPy 7.3.7 doesn't clear this anymore", strict=False
101101
)
102-
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
103102
def test_to_python():
104103
mat = m.Matrix(5, 4)
105104
assert memoryview(mat).shape == (5, 4)
@@ -120,19 +119,20 @@ def test_to_python():
120119
mat2[2, 3] = 5
121120
assert mat2[2, 3] == 5
122121

123-
cstats = ConstructorStats.get(m.Matrix)
124-
assert cstats.alive() == 1
125-
del mat
126-
pytest.gc_collect()
127-
assert cstats.alive() == 1
128-
del mat2 # holds a mat reference
129-
pytest.gc_collect()
130-
assert cstats.alive() == 0
131-
assert cstats.values() == ["5x4 matrix"]
132-
assert cstats.copy_constructions == 0
133-
# assert cstats.move_constructions >= 0 # Don't invoke any
134-
assert cstats.copy_assignments == 0
135-
assert cstats.move_assignments == 0
122+
if not env.GRAALPY:
123+
cstats = ConstructorStats.get(m.Matrix)
124+
assert cstats.alive() == 1
125+
del mat
126+
pytest.gc_collect()
127+
assert cstats.alive() == 1
128+
del mat2 # holds a mat reference
129+
pytest.gc_collect()
130+
assert cstats.alive() == 0
131+
assert cstats.values() == ["5x4 matrix"]
132+
assert cstats.copy_constructions == 0
133+
# assert cstats.move_constructions >= 0 # Don't invoke any
134+
assert cstats.copy_assignments == 0
135+
assert cstats.move_assignments == 0
136136

137137

138138
def test_inherited_protocol():

Diff for: tests/test_cpp_conduit.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import home_planet_very_lonely_traveler
88
import pytest
99

10-
import env # noqa: F401
10+
import env
1111
from pybind11_tests import cpp_conduit as home_planet
1212

1313

@@ -21,15 +21,17 @@ def test_premium_traveler_getattr_actually_exists():
2121
assert t_h.secret_name == "PremiumTraveler GetAttr: secret_name points: 7"
2222

2323

24-
@pytest.mark.xfail("env.GRAALPY", reason="TODO should get fixed on GraalPy side")
2524
def test_call_cpp_conduit_success():
2625
t_h = home_planet.Traveler("home")
2726
cap = t_h._pybind11_conduit_v1_(
2827
home_planet.PYBIND11_PLATFORM_ABI_ID,
2928
home_planet.cpp_type_info_capsule_Traveler,
3029
b"raw_pointer_ephemeral",
3130
)
32-
assert cap.__class__.__name__ == "PyCapsule"
31+
assert cap.__class__.__name__ == "PyCapsule" or (
32+
# Note: this will become unnecessary in the next GraalPy release
33+
env.GRAALPY and cap.__class__.__name__ == "capsule"
34+
)
3335

3436

3537
def test_call_cpp_conduit_platform_abi_id_mismatch():

Diff for: tests/test_methods_and_attributes.py

+26-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
import env # noqa: F401
7+
import env
88
from pybind11_tests import ConstructorStats
99
from pybind11_tests import methods_and_attributes as m
1010

@@ -19,7 +19,6 @@
1919
)
2020

2121

22-
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
2322
def 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

8484
def 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")
300299
def 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

Diff for: tests/test_modules.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def test_nested_modules():
2525
assert ms.submodule_func() == "submodule_func()"
2626

2727

28-
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
2928
def test_reference_internal():
3029
b = ms.B()
3130
assert str(b.get_a1()) == "A[1]"
@@ -40,24 +39,25 @@ def test_reference_internal():
4039
assert str(b.get_a2()) == "A[43]"
4140
assert str(b.a2) == "A[43]"
4241

43-
astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B)
44-
assert astats.alive() == 2
45-
assert bstats.alive() == 1
46-
del b
47-
assert astats.alive() == 0
48-
assert bstats.alive() == 0
49-
assert astats.values() == ["1", "2", "42", "43"]
50-
assert bstats.values() == []
51-
assert astats.default_constructions == 0
52-
assert bstats.default_constructions == 1
53-
assert astats.copy_constructions == 0
54-
assert bstats.copy_constructions == 0
55-
# assert astats.move_constructions >= 0 # Don't invoke any
56-
# assert bstats.move_constructions >= 0 # Don't invoke any
57-
assert astats.copy_assignments == 2
58-
assert bstats.copy_assignments == 0
59-
assert astats.move_assignments == 0
60-
assert bstats.move_assignments == 0
42+
if not env.GRAALPY:
43+
astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B)
44+
assert astats.alive() == 2
45+
assert bstats.alive() == 1
46+
del b
47+
assert astats.alive() == 0
48+
assert bstats.alive() == 0
49+
assert astats.values() == ["1", "2", "42", "43"]
50+
assert bstats.values() == []
51+
assert astats.default_constructions == 0
52+
assert bstats.default_constructions == 1
53+
assert astats.copy_constructions == 0
54+
assert bstats.copy_constructions == 0
55+
# assert astats.move_constructions >= 0 # Don't invoke any
56+
# assert bstats.move_constructions >= 0 # Don't invoke any
57+
assert astats.copy_assignments == 2
58+
assert bstats.copy_assignments == 0
59+
assert astats.move_assignments == 0
60+
assert bstats.move_assignments == 0
6161

6262

6363
def test_importing():

Diff for: tests/test_multiple_inheritance.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
import env # noqa: F401
5+
import env
66
from pybind11_tests import ConstructorStats
77
from pybind11_tests import multiple_inheritance as m
88

@@ -272,16 +272,16 @@ def test_mi_dynamic_attributes():
272272
assert d.dynamic == 1
273273

274274

275-
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
276275
def test_mi_unaligned_base():
277276
"""Returning an offset (non-first MI) base class pointer should recognize the instance"""
278277

279278
n_inst = ConstructorStats.detail_reg_inst()
280279

281280
c = m.I801C()
282281
d = m.I801D()
283-
# + 4 below because we have the two instances, and each instance has offset base I801B2
284-
assert ConstructorStats.detail_reg_inst() == n_inst + 4
282+
if not env.GRAALPY:
283+
# + 4 below because we have the two instances, and each instance has offset base I801B2
284+
assert ConstructorStats.detail_reg_inst() == n_inst + 4
285285
b1c = m.i801b1_c(c)
286286
assert b1c is c
287287
b2c = m.i801b2_c(c)
@@ -291,14 +291,14 @@ def test_mi_unaligned_base():
291291
b2d = m.i801b2_d(d)
292292
assert b2d is d
293293

294-
assert ConstructorStats.detail_reg_inst() == n_inst + 4 # no extra instances
295-
del c, b1c, b2c
296-
assert ConstructorStats.detail_reg_inst() == n_inst + 2
297-
del d, b1d, b2d
298-
assert ConstructorStats.detail_reg_inst() == n_inst
294+
if not env.GRAALPY:
295+
assert ConstructorStats.detail_reg_inst() == n_inst + 4 # no extra instances
296+
del c, b1c, b2c
297+
assert ConstructorStats.detail_reg_inst() == n_inst + 2
298+
del d, b1d, b2d
299+
assert ConstructorStats.detail_reg_inst() == n_inst
299300

300301

301-
@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
302302
def test_mi_base_return():
303303
"""Tests returning an offset (non-first MI) base class pointer to a derived instance"""
304304

@@ -314,7 +314,8 @@ def test_mi_base_return():
314314
assert d1.a == 1
315315
assert d1.b == 2
316316

317-
assert ConstructorStats.detail_reg_inst() == n_inst + 4
317+
if not env.GRAALPY:
318+
assert ConstructorStats.detail_reg_inst() == n_inst + 4
318319

319320
c2 = m.i801c_b2()
320321
assert type(c2) is m.I801C
@@ -326,12 +327,13 @@ def test_mi_base_return():
326327
assert d2.a == 1
327328
assert d2.b == 2
328329

329-
assert ConstructorStats.detail_reg_inst() == n_inst + 8
330+
if not env.GRAALPY:
331+
assert ConstructorStats.detail_reg_inst() == n_inst + 8
330332

331-
del c2
332-
assert ConstructorStats.detail_reg_inst() == n_inst + 6
333-
del c1, d1, d2
334-
assert ConstructorStats.detail_reg_inst() == n_inst
333+
del c2
334+
assert ConstructorStats.detail_reg_inst() == n_inst + 6
335+
del c1, d1, d2
336+
assert ConstructorStats.detail_reg_inst() == n_inst
335337

336338
# Returning an unregistered derived type with a registered base; we won't
337339
# pick up the derived type, obviously, but should still work (as an object

0 commit comments

Comments
 (0)