pyo3/pytests/tests/test_misc.py

51 lines
1.5 KiB
Python
Raw Normal View History

import importlib
import platform
import sys
import pyo3_pytests.misc
import pytest
def test_issue_219():
# Should not deadlock
pyo3_pytests.misc.issue_219()
@pytest.mark.xfail(
platform.python_implementation() == "CPython" and sys.version_info < (3, 9),
reason="Cannot identify subinterpreters on Python older than 3.9",
)
def test_multiple_imports_same_interpreter_ok():
spec = importlib.util.find_spec("pyo3_pytests.pyo3_pytests")
module = importlib.util.module_from_spec(spec)
assert dir(module) == dir(pyo3_pytests.pyo3_pytests)
@pytest.mark.xfail(
platform.python_implementation() == "CPython" and sys.version_info < (3, 9),
reason="Cannot identify subinterpreters on Python older than 3.9",
)
@pytest.mark.skipif(
platform.python_implementation() == "PyPy",
reason="PyPy does not support subinterpreters",
)
def test_import_in_subinterpreter_forbidden():
import _xxsubinterpreters
2023-09-29 12:08:47 +00:00
if sys.version_info < (3, 12):
expected_error = "PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576"
else:
expected_error = "module pyo3_pytests.pyo3_pytests does not support loading in subinterpreters"
sub_interpreter = _xxsubinterpreters.create()
with pytest.raises(
_xxsubinterpreters.RunFailedError,
2023-09-29 12:08:47 +00:00
match=expected_error,
):
_xxsubinterpreters.run_string(
sub_interpreter, "import pyo3_pytests.pyo3_pytests"
)
_xxsubinterpreters.destroy(sub_interpreter)