diff --git a/nox/virtualenv.py b/nox/virtualenv.py index d1d13e9e..842ade47 100644 --- a/nox/virtualenv.py +++ b/nox/virtualenv.py @@ -384,7 +384,17 @@ def _check_reused_environment_type(self) -> bool: return False def _check_reused_environment_interpreter(self) -> bool: - """Check if reused environment interpreter is the same.""" + """ + Check if reused environment interpreter is the same. Currently only checks if + NOX_ENABLE_STALENESS_CHECK is set in the environment. See + + * https://github.com/wntrblm/nox/issues/449#issuecomment-860030890 + * https://github.com/wntrblm/nox/issues/441 + * https://github.com/pypa/virtualenv/issues/2130 + """ + if not os.environ.get("NOX_ENABLE_STALENESS_CHECK", ""): + return True + original = self._read_base_prefix_from_pyvenv_cfg() program = ( "import sys; sys.stdout.write(getattr(sys, 'real_prefix', sys.base_prefix))" diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py index a6a60652..dd185d10 100644 --- a/tests/test_virtualenv.py +++ b/tests/test_virtualenv.py @@ -574,7 +574,8 @@ def test_create_reuse_oldstyle_virtualenv_environment(make_one): @pytest.mark.skipif(IS_WINDOWS, reason="Avoid 'No pyvenv.cfg file' error on Windows.") -def test_inner_functions_reusing_venv(make_one): +def test_inner_functions_reusing_venv(make_one, monkeypatch): + monkeypatch.setenv("NOX_ENABLE_STALENESS_CHECK", "1") venv, location = make_one(reuse_existing=True) venv.create()