pytest-dev / pytest-dev/pytest
Running pytest in a sub-interpreter
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Python 3.14 added a new module concurrent.interpreters which allows creating isolated sub-interpreters with their own GIL. I like the concept and experimented it with it a bit in pytest-xdist/execnet, trying to use sub-interperters instead of processes. I immediately ran into some problems.
But before getting into xdist and such (which share some issues with #13768, particularly around stdio capturing), the most basic thing is just running pytest in a single sub-interpreter:
#!/usr/bin/env python
import sys
from concurrent import interpreters
interp = interpreters.create()
interp.prepare_main(args=tuple(sys.argv[1:]))
interp.exec("""
import pytest
pytest.main(list(args))
""")
Here are the problems this runs into:
-
faulthandlercannot be imported in a sub-interpreter. This may be a fundamental issue as faulthandler is a process-wide concept (https://github.com/python/cpython/issues/101509). I am not sure yet. To make this work we may want to disable auto-loading the faulthandler plugin and skip its tests (or run them in a subprocess) when running under a sub-interpreter. -
multiprocessing.Poolused by a couple of our teststesting/acceptance_test.py::TestGeneralUsage::test_config_errorandtesting/_py/test_local.py::TestLocalPath::test_make_numbered_dir_multiprocess_safeis incompatible https://github.com/python/cpython/issues/140057 -
readlineimported by testtest_libedit_workaroundis incompatible
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided sub-interpreter script and trace pytest startup, especially automatic faulthandler loading. Run the named tests in testing/acceptance_test.py and testing/_py/test_local.py, along with test_libedit_workaround, to reproduce the listed incompatibilities. Done means the supported sub-interpreter behavior and any skipped or subprocess-run tests are documented by passing coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100