pytest-dev / pytest-dev/pytest

Running pytest in a sub-interpreter

Open
#13,809 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement type: selftests
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:

  • faulthandler cannot 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.Pool used by a couple of our tests testing/acceptance_test.py::TestGeneralUsage::test_config_error and testing/_py/test_local.py::TestLocalPath::test_make_numbered_dir_multiprocess_safe is incompatible https://github.com/python/cpython/issues/140057

  • readline imported by test test_libedit_workaround is incompatible

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.