Skip to content

Commit 57e27c1

Browse files
tests: skip some flaky gil tests on nogil (#5699)
* tests: skip some flaky gil tests on nogil Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Update test_gil_scoped.py * style: pre-commit fixes --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1c10d5e commit 57e27c1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/test_gil_scoped.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
import env
1111
from pybind11_tests import gil_scoped as m
1212

13+
skipif_not_free_threaded = pytest.mark.skipif(
14+
not getattr(sys, "_is_gil_enabled", lambda: True)(),
15+
reason="Flaky without the GIL",
16+
)
17+
1318

1419
class ExtendedVirtClass(m.VirtClass):
1520
def virtual_func(self):
@@ -155,7 +160,7 @@ def _intentional_deadlock():
155160
m.intentional_deadlock()
156161

157162

158-
ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = ALL_BASIC_TESTS + (_intentional_deadlock,)
163+
ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = (*ALL_BASIC_TESTS, _intentional_deadlock)
159164

160165

161166
def _run_in_process(target, *args, **kwargs):
@@ -227,6 +232,7 @@ def test_run_in_process_one_thread(test_fn):
227232
assert _run_in_process(_run_in_threads, test_fn, num_threads=1, parallel=False) == 0
228233

229234

235+
@skipif_not_free_threaded
230236
@pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads")
231237
@pytest.mark.parametrize("test_fn", ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK)
232238
@pytest.mark.skipif(
@@ -256,7 +262,13 @@ def test_run_in_process_multiple_threads_sequential(test_fn):
256262

257263

258264
@pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads")
259-
@pytest.mark.parametrize("test_fn", ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK)
265+
@pytest.mark.parametrize(
266+
"test_fn",
267+
[
268+
*ALL_BASIC_TESTS,
269+
pytest.param(_intentional_deadlock, marks=skipif_not_free_threaded),
270+
],
271+
)
260272
@pytest.mark.skipif(
261273
"env.GRAALPY",
262274
reason="GraalPy transiently complains about unfinished threads at process exit",

0 commit comments

Comments
 (0)