From 69dc33a461ae74621c855483ad060ea72ab796c4 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Fri, 25 May 2018 15:50:38 -0700 Subject: [PATCH 1/2] Fix testcmdline when it is run with py.test -n0 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. --- mypy/test/testcmdline.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 40ea781ce1b9..0f455f92f738 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -11,7 +11,7 @@ from typing import List -from mypy.test.config import test_temp_dir +from mypy.test.config import test_temp_dir, PREFIX from mypy.test.data import fix_cobertura_filename from mypy.test.data import DataDrivenTestCase, DataSuite from mypy.test.helpers import assert_string_arrays_equal, normalize_error_messages @@ -48,10 +48,12 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None: args.append('--no-site-packages') # Type check the program. fixed = [python3_path, '-m', 'mypy'] + env = {'PYTHONPATH': PREFIX} process = subprocess.Popen(fixed + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - cwd=test_temp_dir) + cwd=test_temp_dir, + env=env) outb = process.stdout.read() # Split output into lines. out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()] From f5a831d6b6e2125c9e1da97f02f779d4ae64bf50 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Fri, 25 May 2018 16:32:35 -0700 Subject: [PATCH 2/2] Hang onto the existing environment or it fails on windows --- mypy/test/testcmdline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 0f455f92f738..2a8b25687a75 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -48,7 +48,8 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None: args.append('--no-site-packages') # Type check the program. fixed = [python3_path, '-m', 'mypy'] - env = {'PYTHONPATH': PREFIX} + env = os.environ.copy() + env['PYTHONPATH'] = PREFIX process = subprocess.Popen(fixed + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,