Skip to content

Commit

Permalink
Fix environments not being reused due to wrong Python lookup (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjolowicz authored May 24, 2021
1 parent a6539a7 commit e012b60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 4 additions & 2 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,11 @@ def _check_reused_environment_interpreter(self) -> bool:
"""Check if reused environment interpreter is the same."""
program = "import sys; print(getattr(sys, 'real_prefix', sys.base_prefix))"
original = nox.command.run(
[self._resolved_interpreter, "-c", program], silent=True
[self._resolved_interpreter, "-c", program], silent=True, log=False
)
created = nox.command.run(
["python", "-c", program], silent=True, log=False, paths=self.bin_paths
)
created = nox.command.run(["python", "-c", program], silent=True)
return original == created

@property
Expand Down
11 changes: 4 additions & 7 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,20 +410,17 @@ def test_create_reuse_venv_environment(make_one):
venv, location = make_one(reuse_existing=True, venv=True)
venv.create()

# Use a spurious occurrence of "virtualenv" in the pyvenv.cfg.
pyvenv_cfg = """\
home = /opt/virtualenv/bin
include-system-site-packages = false
version = 3.9.6
"""
location.join("pyvenv.cfg").write(dedent(pyvenv_cfg))
# Place a spurious occurrence of "virtualenv" in the pyvenv.cfg.
pyvenv_cfg = location.join("pyvenv.cfg")
pyvenv_cfg.write(pyvenv_cfg.read() + "bogus = virtualenv\n")

reused = not venv.create()

# The environment should be detected as venv-style and reused.
assert reused


@pytest.mark.skipif(IS_WINDOWS, reason="Avoid 'No pyvenv.cfg file' error on Windows.")
def test_create_reuse_oldstyle_virtualenv_environment(make_one):
venv, location = make_one(reuse_existing=True)
venv.create()
Expand Down

0 comments on commit e012b60

Please sign in to comment.