pytest-dev / pytest-dev/pytest
Pytester.syspathinsert() has no effect when using runpytest_subprocess()
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Pytester.syspathinsert() uses monkeypatch to temporarily update sys.path for the length of the test. However, runpytest_subprocess() starts a new process to without any knowledge of requested changes to sys.path.
Using pytest 7.2.0, the first test case will pass, but the second will fail.
from pytest import Pytester
SOME_DIR = "foobar"
def test_syspathinsert__in_process__path_exists(pytester: Pytester):
pytester.syspathinsert(SOME_DIR)
pytester.makepyfile(
f"""
import sys
def test_foo():
assert "{SOME_DIR}" in sys.path
"""
)
result = pytester.runpytest_inprocess()
result.assert_outcomes(passed=1)
def test_syspathinsert__sub_process__path_exists(pytester: Pytester):
pytester.syspathinsert(SOME_DIR)
pytester.makepyfile(
f"""
import sys
def test_foo():
assert "{SOME_DIR}" in sys.path
"""
)
result = pytester.runpytest_subprocess(timeout=1)
result.assert_outcomes(passed=1)
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 in src/_pytest/pytester.py at Pytester.syspathinsert() and runpytest_subprocess(), then reproduce the issue with the two test cases provided in the report. Compare the in-process and subprocess behavior and add or update coverage for the subprocess case. Done means the subprocess test passes while preserving the existing in-process behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100