Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide staleness check behind a feature flag #451

Merged
merged 4 commits into from
Jun 12, 2021
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
3 changes: 3 additions & 0 deletions nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
["PIP_RESPECT_VIRTUALENV", "PIP_REQUIRE_VIRTUALENV", "__PYVENV_LAUNCHER__"]
)
_SYSTEM = platform.system()
_ENABLE_STALENESS_CHECK = "NOX_ENABLE_STALENESS_CHECK" in os.environ


class InterpreterNotFound(OSError):
Expand Down Expand Up @@ -312,6 +313,8 @@ def __init__(
def _clean_location(self) -> bool:
"""Deletes any existing virtual environment"""
if os.path.exists(self.location):
if self.reuse_existing and not _ENABLE_STALENESS_CHECK:
return False
if (
self.reuse_existing
and self._check_reused_environment_type()
Expand Down
14 changes: 14 additions & 0 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ def test_create_reuse_environment(make_one):
assert reused


@pytest.fixture
def _enable_staleness_check(monkeypatch):
monkeypatch.setattr("nox.virtualenv._ENABLE_STALENESS_CHECK", True)


enable_staleness_check = pytest.mark.usefixtures("_enable_staleness_check")


@enable_staleness_check
def test_create_reuse_environment_with_different_interpreter(make_one, monkeypatch):
venv, location = make_one(reuse_existing=True)
venv.create()
Expand All @@ -367,6 +376,7 @@ def test_create_reuse_environment_with_different_interpreter(make_one, monkeypat
assert not location.join("marker").check()


@enable_staleness_check
def test_create_reuse_stale_venv_environment(make_one):
venv, location = make_one(reuse_existing=True)
venv.create()
Expand All @@ -386,6 +396,7 @@ def test_create_reuse_stale_venv_environment(make_one):
assert not reused


@enable_staleness_check
def test_create_reuse_stale_virtualenv_environment(make_one):
venv, location = make_one(reuse_existing=True, venv=True)
venv.create()
Expand All @@ -410,6 +421,7 @@ def test_create_reuse_stale_virtualenv_environment(make_one):
assert not reused


@enable_staleness_check
def test_create_reuse_venv_environment(make_one):
venv, location = make_one(reuse_existing=True, venv=True)
venv.create()
Expand All @@ -424,6 +436,7 @@ def test_create_reuse_venv_environment(make_one):
assert reused


@enable_staleness_check
@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)
Expand All @@ -442,6 +455,7 @@ def test_create_reuse_oldstyle_virtualenv_environment(make_one):
assert reused


@enable_staleness_check
def test_create_reuse_python2_environment(make_one):
venv, location = make_one(reuse_existing=True, interpreter="2.7")

Expand Down