2022-07-26 18:28:03 +00:00
|
|
|
import importlib
|
|
|
|
import platform
|
2023-09-14 12:40:43 +00:00
|
|
|
import sys
|
2022-07-26 18:28:03 +00:00
|
|
|
|
2021-04-01 23:03:49 +00:00
|
|
|
import pyo3_pytests.misc
|
2022-07-26 18:28:03 +00:00
|
|
|
import pytest
|
2021-04-01 23:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_issue_219():
|
|
|
|
# Should not deadlock
|
|
|
|
pyo3_pytests.misc.issue_219()
|
2022-07-26 18:28:03 +00:00
|
|
|
|
|
|
|
|
2023-09-14 12:40:43 +00:00
|
|
|
@pytest.mark.xfail(
|
|
|
|
platform.python_implementation() == "CPython" and sys.version_info < (3, 9),
|
|
|
|
reason="Cannot identify subinterpreters on Python older than 3.9",
|
|
|
|
)
|
2023-09-11 13:20:39 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2023-09-14 12:40:43 +00:00
|
|
|
@pytest.mark.xfail(
|
|
|
|
platform.python_implementation() == "CPython" and sys.version_info < (3, 9),
|
|
|
|
reason="Cannot identify subinterpreters on Python older than 3.9",
|
|
|
|
)
|
2022-07-26 18:28:03 +00:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
platform.python_implementation() == "PyPy",
|
2023-09-11 13:20:39 +00:00
|
|
|
reason="PyPy does not support subinterpreters",
|
2022-07-26 18:28:03 +00:00
|
|
|
)
|
2023-09-11 13:20:39 +00:00
|
|
|
def test_import_in_subinterpreter_forbidden():
|
|
|
|
import _xxsubinterpreters
|
2022-07-26 18:28:03 +00:00
|
|
|
|
2023-09-11 13:20:39 +00:00
|
|
|
sub_interpreter = _xxsubinterpreters.create()
|
2022-07-26 18:28:03 +00:00
|
|
|
with pytest.raises(
|
2023-09-11 13:20:39 +00:00
|
|
|
_xxsubinterpreters.RunFailedError,
|
|
|
|
match="PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576",
|
2022-07-26 18:28:03 +00:00
|
|
|
):
|
2023-09-11 13:20:39 +00:00
|
|
|
_xxsubinterpreters.run_string(
|
|
|
|
sub_interpreter, "import pyo3_pytests.pyo3_pytests"
|
|
|
|
)
|
|
|
|
|
|
|
|
_xxsubinterpreters.destroy(sub_interpreter)
|