Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Cyril Roelandt
Dane Hillard
David Staheli
David Diaz
Dmitrii Sutiagin a.k.a. f3flight
Ederag
Eli Collins
Eugene Yunak
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/2528.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add env cleanup to envreport - fix PYTHONPATH leak into "envreport" -- by :user:`f3flight`.
6 changes: 5 additions & 1 deletion src/tox/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,11 @@ def tox_runtest_post(venv):
def tox_runenvreport(venv, action):
# write out version dependency information
args = venv.envconfig.list_dependencies_command
output = venv._pcall(args, cwd=venv.envconfig.config.toxinidir, action=action, returnout=True)
env = venv._get_os_environ()
venv.ensure_pip_os_environ_ok(env)
output = venv._pcall(
args, cwd=venv.envconfig.config.toxinidir, action=action, returnout=True, env=env
)
# the output contains a mime-header, skip it
output = output.split("\n\n")[-1]
packages = output.strip().split("\n")
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
VirtualEnv,
getdigest,
prepend_shebang_interpreter,
tox_runenvreport,
tox_testenv_create,
tox_testenv_install_deps,
)
Expand Down Expand Up @@ -1233,3 +1234,17 @@ def test_path_change(tmpdir, mocksession, newconfig, monkeypatch):
path = x.env["PATH"]
assert os.environ["PATH"] in path
assert path.endswith(str(venv.envconfig.config.toxinidir) + "/bin")


def test_runenvreport_pythonpath_discarded(newmocksession, mocker):
mock_os_environ = mocker.patch("tox.venv.VirtualEnv._get_os_environ")
mocksession = newmocksession([], "")
venv = mocksession.getvenv("python")
mock_os_environ.return_value = dict(PYTHONPATH="/some/path/")
mock_pcall = mocker.patch.object(venv, "_pcall")
tox_runenvreport(venv, None)
try:
env = mock_pcall.mock_calls[0].kwargs["env"]
except TypeError: # older pytest (python 3.7 and below)
env = mock_pcall.mock_calls[0][2]["env"]
assert "PYTHONPATH" not in env