diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index adbbaefb8de4..d30d94c49bee 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -62,7 +62,7 @@ def install_package(pkg: str, working_dir = os.path.join(package_path, pkg) with tempfile.TemporaryDirectory() as dir: if use_pip: - install_cmd = [python_executable, '-m', 'pip', 'install', '-b', '{}'.format(dir)] + install_cmd = [python_executable, '-m', 'pip', 'install'] if editable: install_cmd.append('-e') install_cmd.append('.') @@ -72,7 +72,16 @@ def install_package(pkg: str, install_cmd.append('develop') else: install_cmd.append('install') - proc = subprocess.run(install_cmd, cwd=working_dir, stdout=PIPE, stderr=PIPE) + # Note that newer versions of pip (21.3+) don't + # follow this env variable, but this is for compatibility + env = {'PIP_BUILD': dir} + # Inherit environment for Windows + env.update(os.environ) + proc = subprocess.run(install_cmd, + cwd=working_dir, + stdout=PIPE, + stderr=PIPE, + env=env) if proc.returncode != 0: raise Exception(proc.stdout.decode('utf-8') + proc.stderr.decode('utf-8'))