From c4a74c35515ffa675824da3491c9ba86223fa6f0 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 | 48 ++++++++++++------------- tests/test_cpp_conduit.py | 8 +++-- tests/test_methods_and_attributes.py | 49 +++++++++++++------------ tests/test_modules.py | 38 ++++++++++---------- tests/test_multiple_inheritance.py | 34 +++++++++--------- tests/test_sequences_and_iterators.py | 51 +++++++++++++++------------ 6 files changed, 120 insertions(+), 108 deletions(-) diff --git a/tests/test_buffers.py b/tests/test_buffers.py index 3cdd66d6cb..918cd94184 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,15 +82,16 @@ def test_from_python(): for j in range(m4.cols()): assert m3[i, j] == m4[i, j] - cstats = ConstructorStats.get(m.Matrix) - assert cstats.alive() == 1 - del m3, m4 - assert cstats.alive() == 0 - assert cstats.values() == ["2x3 matrix"] - assert cstats.copy_constructions == 0 - # assert cstats.move_constructions >= 0 # Don't invoke any - assert cstats.copy_assignments == 0 - assert cstats.move_assignments == 0 + if not env.GRAALPY: + cstats = ConstructorStats.get(m.Matrix) + assert cstats.alive() == 1 + del m3, m4 + assert cstats.alive() == 0 + assert cstats.values() == ["2x3 matrix"] + assert cstats.copy_constructions == 0 + # assert cstats.move_constructions >= 0 # Don't invoke any + assert cstats.copy_assignments == 0 + assert cstats.move_assignments == 0 # https://foss.heptapod.net/pypy/pypy/-/issues/2444 @@ -99,7 +99,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,19 +119,20 @@ def test_to_python(): mat2[2, 3] = 5 assert mat2[2, 3] == 5 - cstats = ConstructorStats.get(m.Matrix) - assert cstats.alive() == 1 - del mat - pytest.gc_collect() - assert cstats.alive() == 1 - del mat2 # holds a mat reference - pytest.gc_collect() - assert cstats.alive() == 0 - assert cstats.values() == ["5x4 matrix"] - assert cstats.copy_constructions == 0 - # assert cstats.move_constructions >= 0 # Don't invoke any - assert cstats.copy_assignments == 0 - assert cstats.move_assignments == 0 + if not env.GRAALPY: + cstats = ConstructorStats.get(m.Matrix) + assert cstats.alive() == 1 + del mat + pytest.gc_collect() + assert cstats.alive() == 1 + del mat2 # holds a mat reference + pytest.gc_collect() + assert cstats.alive() == 0 + assert cstats.values() == ["5x4 matrix"] + assert cstats.copy_constructions == 0 + # assert cstats.move_constructions >= 0 # Don't invoke any + assert cstats.copy_assignments == 0 + assert cstats.move_assignments == 0 def test_inherited_protocol(): 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..ad7b792f54 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,16 +68,17 @@ def test_methods_and_attributes(): instance1.value = 100 assert str(instance1) == "ExampleMandA[value=100]" - cstats = ConstructorStats.get(m.ExampleMandA) - assert cstats.alive() == 2 - del instance1, instance2 - assert cstats.alive() == 0 - assert cstats.values() == ["32"] - assert cstats.default_constructions == 1 - assert cstats.copy_constructions == 2 - assert cstats.move_constructions >= 2 - assert cstats.copy_assignments == 0 - assert cstats.move_assignments == 0 + if not env.GRAALPY: + cstats = ConstructorStats.get(m.ExampleMandA) + assert cstats.alive() == 2 + del instance1, instance2 + assert cstats.alive() == 0 + assert cstats.values() == ["32"] + assert cstats.default_constructions == 1 + assert cstats.copy_constructions == 2 + assert cstats.move_constructions >= 2 + assert cstats.copy_assignments == 0 + assert cstats.move_assignments == 0 def test_copy_method(): @@ -296,7 +296,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") @@ -314,14 +313,17 @@ def test_dynamic_attributes(): assert not hasattr(instance, "foo") assert hasattr(instance, "bar") - with pytest.raises(TypeError) as excinfo: - instance.__dict__ = [] - assert str(excinfo.value) == "__dict__ must be set to a dictionary, not a 'list'" + if not env.GRAALPY: + with pytest.raises(TypeError) as excinfo: + instance.__dict__ = [] + assert ( + str(excinfo.value) == "__dict__ must be set to a dictionary, not a 'list'" + ) - cstats = ConstructorStats.get(m.DynamicClass) - assert cstats.alive() == 1 - del instance - assert cstats.alive() == 0 + cstats = ConstructorStats.get(m.DynamicClass) + assert cstats.alive() == 1 + del instance + assert cstats.alive() == 0 # Derived classes should work as well class PythonDerivedDynamicClass(m.DynamicClass): @@ -332,9 +334,10 @@ class PythonDerivedDynamicClass(m.DynamicClass): derived.foobar = 100 assert derived.foobar == 100 - assert cstats.alive() == 1 - del derived - assert cstats.alive() == 0 + if not env.GRAALPY: + assert cstats.alive() == 1 + del derived + assert cstats.alive() == 0 # https://foss.heptapod.net/pypy/pypy/-/issues/2447 diff --git a/tests/test_modules.py b/tests/test_modules.py index 286b6486a7..547bc50efb 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,24 +39,25 @@ def test_reference_internal(): assert str(b.get_a2()) == "A[43]" assert str(b.a2) == "A[43]" - astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B) - assert astats.alive() == 2 - assert bstats.alive() == 1 - del b - assert astats.alive() == 0 - assert bstats.alive() == 0 - assert astats.values() == ["1", "2", "42", "43"] - assert bstats.values() == [] - assert astats.default_constructions == 0 - assert bstats.default_constructions == 1 - assert astats.copy_constructions == 0 - assert bstats.copy_constructions == 0 - # assert astats.move_constructions >= 0 # Don't invoke any - # assert bstats.move_constructions >= 0 # Don't invoke any - assert astats.copy_assignments == 2 - assert bstats.copy_assignments == 0 - assert astats.move_assignments == 0 - assert bstats.move_assignments == 0 + if not env.GRAALPY: + astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B) + assert astats.alive() == 2 + assert bstats.alive() == 1 + del b + assert astats.alive() == 0 + assert bstats.alive() == 0 + assert astats.values() == ["1", "2", "42", "43"] + assert bstats.values() == [] + assert astats.default_constructions == 0 + assert bstats.default_constructions == 1 + assert astats.copy_constructions == 0 + assert bstats.copy_constructions == 0 + # assert astats.move_constructions >= 0 # Don't invoke any + # assert bstats.move_constructions >= 0 # Don't invoke any + assert astats.copy_assignments == 2 + assert bstats.copy_assignments == 0 + assert astats.move_assignments == 0 + assert bstats.move_assignments == 0 def test_importing(): diff --git a/tests/test_multiple_inheritance.py b/tests/test_multiple_inheritance.py index 1de5e3c1c5..2453ee5a49 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,14 +291,14 @@ def test_mi_unaligned_base(): b2d = m.i801b2_d(d) assert b2d is d - assert ConstructorStats.detail_reg_inst() == n_inst + 4 # no extra instances - del c, b1c, b2c - assert ConstructorStats.detail_reg_inst() == n_inst + 2 - del d, b1d, b2d - assert ConstructorStats.detail_reg_inst() == n_inst + if not env.GRAALPY: + assert ConstructorStats.detail_reg_inst() == n_inst + 4 # no extra instances + del c, b1c, b2c + assert ConstructorStats.detail_reg_inst() == n_inst + 2 + del d, b1d, b2d + 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 +314,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 +327,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..b0ea82d70f 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,26 +145,28 @@ 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) - assert cstats.alive() == 4 - del it - assert cstats.alive() == 3 - del s - assert cstats.alive() == 2 - del rev - assert cstats.alive() == 1 - del rev2 - assert cstats.alive() == 0 - - assert cstats.values() == [] - assert cstats.default_constructions == 0 - assert cstats.copy_constructions == 0 - assert cstats.move_constructions >= 1 - assert cstats.copy_assignments == 0 - assert cstats.move_assignments == 0 + if not env.GRAALPY: + assert cstats.alive() == 4 + del it + assert cstats.alive() == 3 + del s + assert cstats.alive() == 2 + del rev + assert cstats.alive() == 1 + del rev2 + assert cstats.alive() == 0 + + assert cstats.values() == [] + assert cstats.default_constructions == 0 + assert cstats.copy_constructions == 0 + assert cstats.move_constructions >= 1 + assert cstats.copy_assignments == 0 + assert cstats.move_assignments == 0 def test_sequence_length():