From ebd7898cb4807055b42eafa1f03fa42d7883c7ad Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Thu, 3 Oct 2024 15:48:13 +0200 Subject: [PATCH] Try to narrow down skipped tests --- tests/test_buffers.py | 6 ++++-- tests/test_cpp_conduit.py | 8 +++++--- tests/test_methods_and_attributes.py | 9 ++++++--- tests/test_modules.py | 4 +++- tests/test_multiple_inheritance.py | 26 +++++++++++++++----------- tests/test_sequences_and_iterators.py | 21 ++++++++++++++------- tests/test_virtual_functions.py | 18 ++++++++++-------- 7 files changed, 57 insertions(+), 35 deletions(-) diff --git a/tests/test_buffers.py b/tests/test_buffers.py index 3cdd66d6cb..1aff38ea76 100644 --- a/tests/test_buffers.py +++ b/tests/test_buffers.py @@ -70,7 +70,6 @@ def test_format_descriptor_format_buffer_info_equiv(cpp_name, np_dtype): assert not np_array_is_matching -@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_from_python(): with pytest.raises(RuntimeError) as excinfo: m.Matrix(np.array([1, 2, 3])) # trying to assign a 1D array @@ -83,6 +82,8 @@ def test_from_python(): for j in range(m4.cols()): assert m3[i, j] == m4[i, j] + if env.GRAALPY: + pytest.skip("ConstructorStats is incompatible with GraalPy.") cstats = ConstructorStats.get(m.Matrix) assert cstats.alive() == 1 del m3, m4 @@ -99,7 +100,6 @@ def test_from_python(): @pytest.mark.xfail( env.PYPY, reason="PyPy 7.3.7 doesn't clear this anymore", strict=False ) -@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_to_python(): mat = m.Matrix(5, 4) assert memoryview(mat).shape == (5, 4) @@ -120,6 +120,8 @@ def test_to_python(): mat2[2, 3] = 5 assert mat2[2, 3] == 5 + if env.GRAALPY: + pytest.skip("ConstructorStats is incompatible with GraalPy.") cstats = ConstructorStats.get(m.Matrix) assert cstats.alive() == 1 del mat diff --git a/tests/test_cpp_conduit.py b/tests/test_cpp_conduit.py index fce3400986..eb300587fa 100644 --- a/tests/test_cpp_conduit.py +++ b/tests/test_cpp_conduit.py @@ -7,7 +7,7 @@ import home_planet_very_lonely_traveler import pytest -import env # noqa: F401 +import env from pybind11_tests import cpp_conduit as home_planet @@ -21,7 +21,6 @@ def test_premium_traveler_getattr_actually_exists(): assert t_h.secret_name == "PremiumTraveler GetAttr: secret_name points: 7" -@pytest.mark.xfail("env.GRAALPY", reason="TODO should get fixed on GraalPy side") def test_call_cpp_conduit_success(): t_h = home_planet.Traveler("home") cap = t_h._pybind11_conduit_v1_( @@ -29,7 +28,10 @@ def test_call_cpp_conduit_success(): home_planet.cpp_type_info_capsule_Traveler, b"raw_pointer_ephemeral", ) - assert cap.__class__.__name__ == "PyCapsule" + assert cap.__class__.__name__ == "PyCapsule" or ( + # Note: this will become unnecessary in the next GraalPy release + env.GRAALPY and cap.__class__.__name__ == "capsule" + ) def test_call_cpp_conduit_platform_abi_id_mismatch(): diff --git a/tests/test_methods_and_attributes.py b/tests/test_methods_and_attributes.py index 4298762d51..91c7b7751e 100644 --- a/tests/test_methods_and_attributes.py +++ b/tests/test_methods_and_attributes.py @@ -4,7 +4,7 @@ import pytest -import env # noqa: F401 +import env from pybind11_tests import ConstructorStats from pybind11_tests import methods_and_attributes as m @@ -19,7 +19,6 @@ ) -@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_methods_and_attributes(): instance1 = m.ExampleMandA() instance2 = m.ExampleMandA(32) @@ -69,6 +68,9 @@ def test_methods_and_attributes(): instance1.value = 100 assert str(instance1) == "ExampleMandA[value=100]" + if env.GRAALPY: + pytest.skip("ConstructorStats is incompatible with GraalPy.") + cstats = ConstructorStats.get(m.ExampleMandA) assert cstats.alive() == 2 del instance1, instance2 @@ -296,7 +298,6 @@ def test_property_rvalue_policy(): # https://foss.heptapod.net/pypy/pypy/-/issues/2447 @pytest.mark.xfail("env.PYPY") -@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_dynamic_attributes(): instance = m.DynamicClass() assert not hasattr(instance, "foo") @@ -318,6 +319,8 @@ def test_dynamic_attributes(): instance.__dict__ = [] assert str(excinfo.value) == "__dict__ must be set to a dictionary, not a 'list'" + if env.GRAALPY: + pytest.skip("ConstructorStats is incompatible with GraalPy.") cstats = ConstructorStats.get(m.DynamicClass) assert cstats.alive() == 1 del instance diff --git a/tests/test_modules.py b/tests/test_modules.py index 286b6486a7..436271a701 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -25,7 +25,6 @@ def test_nested_modules(): assert ms.submodule_func() == "submodule_func()" -@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_reference_internal(): b = ms.B() assert str(b.get_a1()) == "A[1]" @@ -40,6 +39,9 @@ def test_reference_internal(): assert str(b.get_a2()) == "A[43]" assert str(b.a2) == "A[43]" + if env.GRAALPY: + pytest.skip("ConstructorStats is incompatible with GraalPy.") + astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B) assert astats.alive() == 2 assert bstats.alive() == 1 diff --git a/tests/test_multiple_inheritance.py b/tests/test_multiple_inheritance.py index 1de5e3c1c5..6f5a656f5d 100644 --- a/tests/test_multiple_inheritance.py +++ b/tests/test_multiple_inheritance.py @@ -2,7 +2,7 @@ import pytest -import env # noqa: F401 +import env from pybind11_tests import ConstructorStats from pybind11_tests import multiple_inheritance as m @@ -272,7 +272,6 @@ def test_mi_dynamic_attributes(): assert d.dynamic == 1 -@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_mi_unaligned_base(): """Returning an offset (non-first MI) base class pointer should recognize the instance""" @@ -280,8 +279,9 @@ def test_mi_unaligned_base(): c = m.I801C() d = m.I801D() - # + 4 below because we have the two instances, and each instance has offset base I801B2 - assert ConstructorStats.detail_reg_inst() == n_inst + 4 + if not env.GRAALPY: + # + 4 below because we have the two instances, and each instance has offset base I801B2 + assert ConstructorStats.detail_reg_inst() == n_inst + 4 b1c = m.i801b1_c(c) assert b1c is c b2c = m.i801b2_c(c) @@ -291,6 +291,9 @@ def test_mi_unaligned_base(): b2d = m.i801b2_d(d) assert b2d is d + if env.GRAALPY: + pytest.skip("ConstructorStats is incompatible with GraalPy.") + assert ConstructorStats.detail_reg_inst() == n_inst + 4 # no extra instances del c, b1c, b2c assert ConstructorStats.detail_reg_inst() == n_inst + 2 @@ -298,7 +301,6 @@ def test_mi_unaligned_base(): assert ConstructorStats.detail_reg_inst() == n_inst -@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_mi_base_return(): """Tests returning an offset (non-first MI) base class pointer to a derived instance""" @@ -314,7 +316,8 @@ def test_mi_base_return(): assert d1.a == 1 assert d1.b == 2 - assert ConstructorStats.detail_reg_inst() == n_inst + 4 + if not env.GRAALPY: + assert ConstructorStats.detail_reg_inst() == n_inst + 4 c2 = m.i801c_b2() assert type(c2) is m.I801C @@ -326,12 +329,13 @@ def test_mi_base_return(): assert d2.a == 1 assert d2.b == 2 - assert ConstructorStats.detail_reg_inst() == n_inst + 8 + if not env.GRAALPY: + assert ConstructorStats.detail_reg_inst() == n_inst + 8 - del c2 - assert ConstructorStats.detail_reg_inst() == n_inst + 6 - del c1, d1, d2 - assert ConstructorStats.detail_reg_inst() == n_inst + del c2 + assert ConstructorStats.detail_reg_inst() == n_inst + 6 + del c1, d1, d2 + assert ConstructorStats.detail_reg_inst() == n_inst # Returning an unregistered derived type with a registered base; we won't # pick up the derived type, obviously, but should still work (as an object diff --git a/tests/test_sequences_and_iterators.py b/tests/test_sequences_and_iterators.py index 78ba3b0f06..20abd29d59 100644 --- a/tests/test_sequences_and_iterators.py +++ b/tests/test_sequences_and_iterators.py @@ -3,7 +3,7 @@ import pytest from pytest import approx # noqa: PT013 -import env # noqa: F401 +import env from pybind11_tests import ConstructorStats from pybind11_tests import sequences_and_iterators as m @@ -107,12 +107,12 @@ def test_sliceable(): assert sliceable[50:60:-1] == (50, 60, -1) -@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") def test_sequence(): cstats = ConstructorStats.get(m.Sequence) s = m.Sequence(5) - assert cstats.values() == ["of size", "5"] + if not env.GRAALPY: + assert cstats.values() == ["of size", "5"] assert "Sequence" in repr(s) assert len(s) == 5 @@ -125,16 +125,19 @@ def test_sequence(): assert s[3] == approx(56.78, rel=1e-05) rev = reversed(s) - assert cstats.values() == ["of size", "5"] + if not env.GRAALPY: + assert cstats.values() == ["of size", "5"] rev2 = s[::-1] - assert cstats.values() == ["of size", "5"] + if not env.GRAALPY: + assert cstats.values() == ["of size", "5"] it = iter(m.Sequence(0)) for _ in range(3): # __next__ must continue to raise StopIteration with pytest.raises(StopIteration): next(it) - assert cstats.values() == ["of size", "0"] + if not env.GRAALPY: + assert cstats.values() == ["of size", "0"] expected = [0, 56.78, 0, 0, 12.34] assert rev == approx(expected, rel=1e-05) @@ -142,10 +145,14 @@ def test_sequence(): assert rev == rev2 rev[0::2] = m.Sequence([2.0, 2.0, 2.0]) - assert cstats.values() == ["of size", "3", "from std::vector"] + if not env.GRAALPY: + assert cstats.values() == ["of size", "3", "from std::vector"] assert rev == approx([2, 56.78, 2, 0, 2], rel=1e-05) + if env.GRAALPY: + pytest.skip("ConstructorStats is incompatible with GraalPy.") + assert cstats.alive() == 4 del it assert cstats.alive() == 3 diff --git a/tests/test_virtual_functions.py b/tests/test_virtual_functions.py index 1b87452a39..617c87b8e0 100644 --- a/tests/test_virtual_functions.py +++ b/tests/test_virtual_functions.py @@ -82,14 +82,16 @@ def get_string2(self): """ ) - if not env.GRAALPY: - cstats = ConstructorStats.get(m.ExampleVirt) - assert cstats.alive() == 3 - del ex12, ex12p, ex12p2 - assert cstats.alive() == 0 - assert cstats.values() == ["10", "11", "17"] - assert cstats.copy_constructions == 0 - assert cstats.move_constructions >= 0 + if env.GRAALPY: + pytest.skip("ConstructorStats is incompatible with GraalPy.") + + cstats = ConstructorStats.get(m.ExampleVirt) + assert cstats.alive() == 3 + del ex12, ex12p, ex12p2 + assert cstats.alive() == 0 + assert cstats.values() == ["10", "11", "17"] + assert cstats.copy_constructions == 0 + assert cstats.move_constructions >= 0 @pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")