diff --git a/tests/pytest.ini b/tests/pytest.ini index ee4ddd5120..6ca7a91362 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -20,4 +20,3 @@ filterwarnings = # bogus numpy ABI warning (see numpy/#432) ignore:.*numpy.dtype size changed.*:RuntimeWarning ignore:.*numpy.ufunc size changed.*:RuntimeWarning - default:The global interpreter lock:RuntimeWarning diff --git a/tests/test_cpp_conduit.py b/tests/test_cpp_conduit.py index eb300587fa..a3c3eba117 100644 --- a/tests/test_cpp_conduit.py +++ b/tests/test_cpp_conduit.py @@ -2,15 +2,32 @@ from __future__ import annotations -import exo_planet_c_api -import exo_planet_pybind11 -import home_planet_very_lonely_traveler +import importlib +import sys + import pytest import env from pybind11_tests import cpp_conduit as home_planet +def import_warns_freethreaded(name): + if name not in sys.modules and not getattr(sys, "_is_gil_enabled", lambda: True)(): + with pytest.warns( + RuntimeWarning, match=f"has been enabled to load module '{name}'" + ): + return importlib.import_module(name) + + return importlib.import_module(name) + + +exo_planet_c_api = import_warns_freethreaded("exo_planet_c_api") +exo_planet_pybind11 = import_warns_freethreaded("exo_planet_pybind11") +home_planet_very_lonely_traveler = import_warns_freethreaded( + "home_planet_very_lonely_traveler" +) + + def test_traveler_getattr_actually_exists(): t_h = home_planet.Traveler("home") assert t_h.any_name == "Traveler GetAttr: any_name luggage: home"