Skip to content

Commit 5051829

Browse files
XuehaiPanhenryiii
authored andcommitted
fix: test critical_section for no-gil only
1 parent 3da3d28 commit 5051829

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

tests/test_scoped_critical_section.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ TEST_SUBMODULE(scoped_critical_section, m) {
127127
.def("get", &BoolWrapper::get)
128128
.def("set", &BoolWrapper::set);
129129
auto BoolWrapperHandle = py::handle(BoolWrapperClass);
130+
(void) BoolWrapperHandle.ptr(); // suppress unused variable warning
130131

131132
#ifdef PYBIND11_HAS_BARRIER
132133
m.attr("has_barrier") = true;

tests/test_scoped_critical_section.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
import pytest
44

5+
import env
56
from pybind11_tests import scoped_critical_section as m
67

78

9+
@pytest.mark.skipif(not env.PY_GIL_DISABLED, reason="requires GIL disabled")
810
@pytest.mark.skipif(not m.has_barrier, reason="no <barrier>")
911
def test_scoped_critical_section() -> None:
1012
for _ in range(64):
1113
assert m.test_scoped_critical_section() is True
1214

1315

16+
@pytest.mark.skipif(not env.PY_GIL_DISABLED, reason="requires GIL disabled")
1417
@pytest.mark.skipif(not m.has_barrier, reason="no <barrier>")
1518
def test_scoped_critical_section2() -> None:
1619
for _ in range(64):
1720
assert m.test_scoped_critical_section2() == (True, True)
1821

1922

23+
@pytest.mark.skipif(not env.PY_GIL_DISABLED, reason="requires GIL disabled")
2024
@pytest.mark.skipif(not m.has_barrier, reason="no <barrier>")
2125
def test_scoped_critical_section2_same_object_no_deadlock() -> None:
2226
for _ in range(64):

0 commit comments

Comments
 (0)