Skip to content

Commit

Permalink
Hide staleness check behind a feature flag (#451)
Browse files Browse the repository at this point in the history
* Hide staleness check behind a feature flag

* Set feature flag for staleness check in unit tests

* Set feature flag for staleness check in Python 2 test
  • Loading branch information
cjolowicz authored Jun 12, 2021
1 parent 2791b70 commit 950015e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 950015e

Please sign in to comment.