From db1618d1981897dc9f87f6efa369b8e6543f4723 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 27 May 2025 01:36:12 -0400 Subject: [PATCH 1/3] tests: skip some flaky gil tests on nogil Signed-off-by: Henry Schreiner --- tests/test_gil_scoped.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_gil_scoped.py b/tests/test_gil_scoped.py index 2db771a508..3ba3c438ca 100644 --- a/tests/test_gil_scoped.py +++ b/tests/test_gil_scoped.py @@ -10,6 +10,11 @@ import env from pybind11_tests import gil_scoped as m +notfreethreaded = pytest.mark.skipif( + not getattr(sys, "_is_gil_enabled", lambda: True)(), + reason="Flaky without the GIL", +) + class ExtendedVirtClass(m.VirtClass): def virtual_func(self): @@ -155,7 +160,7 @@ def _intentional_deadlock(): m.intentional_deadlock() -ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = ALL_BASIC_TESTS + (_intentional_deadlock,) +ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = (*ALL_BASIC_TESTS, _intentional_deadlock) def _run_in_process(target, *args, **kwargs): @@ -227,6 +232,7 @@ def test_run_in_process_one_thread(test_fn): assert _run_in_process(_run_in_threads, test_fn, num_threads=1, parallel=False) == 0 +@notfreethreaded @pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads") @pytest.mark.parametrize("test_fn", ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK) @pytest.mark.skipif( @@ -256,7 +262,10 @@ def test_run_in_process_multiple_threads_sequential(test_fn): @pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads") -@pytest.mark.parametrize("test_fn", ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK) +@pytest.mark.parametrize( + "test_fn", + [*ALL_BASIC_TESTS, pytest.param(_intentional_deadlock, marks=notfreethreaded)], +) @pytest.mark.skipif( "env.GRAALPY", reason="GraalPy transiently complains about unfinished threads at process exit", From c243f0a573bdc8493bf2b60fd3a1bbf452038987 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 27 May 2025 09:07:22 -0400 Subject: [PATCH 2/3] Update test_gil_scoped.py --- tests/test_gil_scoped.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_gil_scoped.py b/tests/test_gil_scoped.py index 3ba3c438ca..f9308985b2 100644 --- a/tests/test_gil_scoped.py +++ b/tests/test_gil_scoped.py @@ -10,7 +10,7 @@ import env from pybind11_tests import gil_scoped as m -notfreethreaded = pytest.mark.skipif( +skipif_not_free_threaded = pytest.mark.skipif( not getattr(sys, "_is_gil_enabled", lambda: True)(), reason="Flaky without the GIL", ) @@ -232,7 +232,7 @@ def test_run_in_process_one_thread(test_fn): assert _run_in_process(_run_in_threads, test_fn, num_threads=1, parallel=False) == 0 -@notfreethreaded +@skipif_not_free_threaded @pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads") @pytest.mark.parametrize("test_fn", ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK) @pytest.mark.skipif( @@ -264,7 +264,7 @@ def test_run_in_process_multiple_threads_sequential(test_fn): @pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads") @pytest.mark.parametrize( "test_fn", - [*ALL_BASIC_TESTS, pytest.param(_intentional_deadlock, marks=notfreethreaded)], + [*ALL_BASIC_TESTS, pytest.param(_intentional_deadlock, marks=skipif_not_free_threaded)], ) @pytest.mark.skipif( "env.GRAALPY", From f6494b9bf2305c905d44a0496a458c5a35061c43 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 27 May 2025 13:08:18 +0000 Subject: [PATCH 3/3] style: pre-commit fixes --- tests/test_gil_scoped.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_gil_scoped.py b/tests/test_gil_scoped.py index f9308985b2..d7efc9af6b 100644 --- a/tests/test_gil_scoped.py +++ b/tests/test_gil_scoped.py @@ -264,7 +264,10 @@ def test_run_in_process_multiple_threads_sequential(test_fn): @pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads") @pytest.mark.parametrize( "test_fn", - [*ALL_BASIC_TESTS, pytest.param(_intentional_deadlock, marks=skipif_not_free_threaded)], + [ + *ALL_BASIC_TESTS, + pytest.param(_intentional_deadlock, marks=skipif_not_free_threaded), + ], ) @pytest.mark.skipif( "env.GRAALPY",