Skip to content

Commit

Permalink
tests: increase coverage of check again
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Feb 26, 2024
1 parent 152bb3d commit 4691bdd
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ def test_create(monkeypatch, make_one):
assert dir_.join("test.txt").check()


def test_create_reuse_environment(make_one):
def test_create_reuse_environment(make_one, monkeypatch):
# Making the reuse requirement more strict
monkeypatch.setenv("NOX_ENABLE_STALENESS_CHECK", "1")

venv, location = make_one(reuse_existing=True)
venv.create()

Expand Down Expand Up @@ -430,36 +433,20 @@ def test_create_reuse_stale_venv_environment(make_one):

reused = not venv.create()

# The environment is not reused because it is a uv-style
# environment.
assert not reused


def test_stale_venv_to_conda_environment(make_one):
def test_not_stale_virtualenv_environment(make_one):
venv, location = make_one(reuse_existing=True, venv_backend="virtualenv")
venv.create()

venv, location = make_one(reuse_existing=True, venv_backend="virtualenv")
reused = venv.create()
reused = not venv.create()

# The environment is not reused because it is now venv style
# environment.
assert not reused
assert reused


@has_conda
def test_stale_conda_to_venv_environment(make_one):
venv, location = make_one(reuse_existing=True, venv_backend="conda")
venv.create()

venv, location = make_one(reuse_existing=True, venv_backend="virtualenv")
reused = venv._check_reused_environment_type()

# The environment is not reused because it is now conda style
# environment.
assert not reused


def test_stale_virtualenv_to_conda_environment(make_one):
venv, location = make_one(reuse_existing=True, venv_backend="virtualenv")
venv.create()
Expand All @@ -472,11 +459,12 @@ def test_stale_virtualenv_to_conda_environment(make_one):
assert not reused


@has_conda
def test_reuse_conda_environment(make_one):
venv, location = make_one(reuse_existing=True, venv_backend="conda")
venv, _ = make_one(reuse_existing=True, venv_backend="conda")
venv.create()

venv, location = make_one(reuse_existing=True, venv_backend="conda")
venv, _ = make_one(reuse_existing=True, venv_backend="conda")
reused = not venv.create()

assert reused
Expand All @@ -489,20 +477,22 @@ def test_reuse_conda_environment(make_one):
("venv", "virtualenv", True),
("virtualenv", "uv", True),
pytest.param("uv", "virtualenv", False, marks=has_uv),
pytest.param("conda", "virtualenv", False, marks=has_conda),
],
)
def test_stale_environment(make_one, frm, to, result):
venv, location = make_one(reuse_existing=True, venv_backend=frm)
venv, _ = make_one(reuse_existing=True, venv_backend=frm)
venv.create()

venv.venv_backend = to
venv, _ = make_one(reuse_existing=True, venv_backend=to)
reused = venv._check_reused_environment_type()

assert reused == result


@has_uv
def test_create_reuse_stale_virtualenv_environment(make_one):
def test_create_reuse_stale_virtualenv_environment(make_one, monkeypatch):
monkeypatch.setenv("NOX_ENABLE_STALENESS_CHECK", "1")
venv, location = make_one(reuse_existing=True, venv_backend="venv")
venv.create()

Expand Down

0 comments on commit 4691bdd

Please sign in to comment.