Open
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)