Skip to content

Commit 2624d4a

Browse files
henryiiirwgk
andauthored
tests: expect free-threaded import warnings (#5680)
* tests: expect free-threaded import warnings Signed-off-by: Henry Schreiner <[email protected]> * Update tests/test_cpp_conduit.py Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]> * Update tests/test_cpp_conduit.py --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]>
1 parent fc888f7 commit 2624d4a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

tests/pytest.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ filterwarnings =
2020
# bogus numpy ABI warning (see numpy/#432)
2121
ignore:.*numpy.dtype size changed.*:RuntimeWarning
2222
ignore:.*numpy.ufunc size changed.*:RuntimeWarning
23-
default:The global interpreter lock:RuntimeWarning

tests/test_cpp_conduit.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,32 @@
22

33
from __future__ import annotations
44

5-
import exo_planet_c_api
6-
import exo_planet_pybind11
7-
import home_planet_very_lonely_traveler
5+
import importlib
6+
import sys
7+
88
import pytest
99

1010
import env
1111
from pybind11_tests import cpp_conduit as home_planet
1212

1313

14+
def import_warns_freethreaded(name):
15+
if name not in sys.modules and not getattr(sys, "_is_gil_enabled", lambda: True)():
16+
with pytest.warns(
17+
RuntimeWarning, match=f"has been enabled to load module '{name}'"
18+
):
19+
return importlib.import_module(name)
20+
21+
return importlib.import_module(name)
22+
23+
24+
exo_planet_c_api = import_warns_freethreaded("exo_planet_c_api")
25+
exo_planet_pybind11 = import_warns_freethreaded("exo_planet_pybind11")
26+
home_planet_very_lonely_traveler = import_warns_freethreaded(
27+
"home_planet_very_lonely_traveler"
28+
)
29+
30+
1431
def test_traveler_getattr_actually_exists():
1532
t_h = home_planet.Traveler("home")
1633
assert t_h.any_name == "Traveler GetAttr: any_name luggage: home"

0 commit comments

Comments
 (0)