Skip to content

Commit

Permalink
Pass the copy of existing environments to the subprocesses
Browse files Browse the repository at this point in the history
Unset PYTHONPATH in virtual environments as tests running there
only need to see that env's paths in sys.path.
  • Loading branch information
befeleme committed Feb 24, 2022
1 parent 6193a69 commit b2dded8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions setuptools/tests/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class VirtualEnv(jaraco.envs.VirtualEnv):
def run(self, cmd, *args, **kwargs):
cmd = [self.exe(cmd[0])] + cmd[1:]
kwargs = {"cwd": self.root, **kwargs} # Allow overriding
# If no environment was passed as an argument
# create a copy of the current env to use when spawning a subprocess
# Unset PYTHONPATH - tests in venv need only that venv's paths in sys.path
env = kwargs.get("env") or dict(os.environ)
if "PYTHONPATH" in env:
del env["PYTHONPATH"]
kwargs["env"] = env
return subprocess.check_output(cmd, *args, **kwargs)


Expand Down
5 changes: 4 additions & 1 deletion setuptools/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ def venv(tmp_path, setuptools_wheel):
env = environment.VirtualEnv()
env.root = path.Path(tmp_path / 'venv')
env.req = str(setuptools_wheel)
return env.create()
# Don't pass PYTHONPATH from the current environment to the created venv
# It only needs its own paths in sys.path
with contexts.environment(PYTHONPATH=None):
return env.create()


@pytest.fixture
Expand Down

0 comments on commit b2dded8

Please sign in to comment.