Skip to content

tests: expect free-threaded import warnings #5680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 20 additions & 3 deletions tests/test_cpp_conduit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down