Skip to content

Commit 7eebb8f

Browse files
msullivangvanrossum
authored andcommitted
Fix testcmdline when it is run with py.test -n0 (#5113)
The test runner sets PYTHONPATH when parallelized but not with -n0. Our subprocess was depending on this to find mypy. We should set up the state we care about ourselves, so just do that. The common failure mode here was the tests failing, but I also ran into a more terrifying mode where it was invoking my installed system mypy! This is basically the same fix elazarg proposed in #4127 but that never went anywhere for unclear reasons. Fixes #4127.
1 parent c9a5d56 commit 7eebb8f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mypy/test/testcmdline.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from typing import List
1313

14-
from mypy.test.config import test_temp_dir
14+
from mypy.test.config import test_temp_dir, PREFIX
1515
from mypy.test.data import fix_cobertura_filename
1616
from mypy.test.data import DataDrivenTestCase, DataSuite
1717
from mypy.test.helpers import assert_string_arrays_equal, normalize_error_messages
@@ -48,10 +48,13 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
4848
args.append('--no-site-packages')
4949
# Type check the program.
5050
fixed = [python3_path, '-m', 'mypy']
51+
env = os.environ.copy()
52+
env['PYTHONPATH'] = PREFIX
5153
process = subprocess.Popen(fixed + args,
5254
stdout=subprocess.PIPE,
5355
stderr=subprocess.STDOUT,
54-
cwd=test_temp_dir)
56+
cwd=test_temp_dir,
57+
env=env)
5558
outb = process.stdout.read()
5659
# Split output into lines.
5760
out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()]

0 commit comments

Comments
 (0)