Skip to content

Commit e4ed615

Browse files
committed
tests: conda marker
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent 9d0b90f commit e4ed615

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ filterwarnings = [ "error" ]
144144
log_cli_level = "INFO"
145145
testpaths = [ "tests" ]
146146
pythonpath = [ ".github/" ]
147+
markers = [
148+
"conda: test requires conda",
149+
]
147150

148151
[tool.coverage]
149152
run.branch = true

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
from __future__ import annotations
1515

1616
import re
17+
import shutil
1718
from pathlib import Path
1819
from string import Template
1920
from typing import Callable
2021

2122
import pytest
2223

24+
HAS_CONDA = shutil.which("conda") is not None
25+
2326

2427
@pytest.fixture(autouse=True)
2528
def reset_color_envvars(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -58,3 +61,15 @@ def generate_noxfile(**option_mapping: str | bool) -> str:
5861
return str(path)
5962

6063
return generate_noxfile
64+
65+
66+
@pytest.hookimpl(tryfirst=True)
67+
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
68+
for item in items:
69+
if "make_conda" in getattr(item, "fixturenames", ()):
70+
item.add_marker("conda")
71+
if "conda" in item.keywords:
72+
item.add_marker(
73+
pytest.mark.skipif(not HAS_CONDA, reason="Missing conda command.")
74+
)
75+
item.add_marker(pytest.mark.xdist_group(name="conda"))

tests/test_sessions.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@
4040
from nox import _options
4141
from nox.logger import logger
4242

43-
HAS_CONDA = shutil.which("conda") is not None
44-
has_conda = pytest.mark.skipif(not HAS_CONDA, reason="Missing conda command.")(
45-
pytest.mark.xdist_group(name="conda")
46-
)
47-
4843
DIR = Path(__file__).parent.resolve()
4944

5045

@@ -1152,7 +1147,7 @@ def test__create_venv(self, create: mock.Mock) -> None:
11521147
"nox.virtualenv.CondaEnv.create",
11531148
"conda",
11541149
nox.virtualenv.CondaEnv,
1155-
marks=has_conda,
1150+
marks=pytest.mark.conda,
11561151
),
11571152
],
11581153
)

tests/test_virtualenv.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@
3939
from nox.virtualenv import CondaEnv, ProcessEnv, VirtualEnv
4040

4141
IS_WINDOWS = sys.platform.startswith("win")
42-
HAS_CONDA = shutil.which("conda") is not None
4342
HAS_UV = shutil.which("uv") is not None
4443
RAISE_ERROR = "RAISE_ERROR"
4544
VIRTUALENV_VERSION = metadata.version("virtualenv")
4645

4746
has_uv = pytest.mark.skipif(not HAS_UV, reason="Missing uv command.")
48-
has_conda = pytest.mark.skipif(not HAS_CONDA, reason="Missing conda command.")(
49-
pytest.mark.xdist_group(name="conda")
50-
)
5147

5248

5349
class TextProcessResult(NamedTuple):
@@ -173,7 +169,6 @@ def test_condaenv_constructor_explicit(
173169
assert venv.reuse_existing is True
174170

175171

176-
@has_conda
177172
def test_condaenv_create(make_conda: Callable[..., tuple[CondaEnv, Path]]) -> None:
178173
venv, dir_ = make_conda()
179174
venv.create()
@@ -202,7 +197,6 @@ def test_condaenv_create(make_conda: Callable[..., tuple[CondaEnv, Path]]) -> No
202197
assert venv._reused
203198

204199

205-
@has_conda
206200
def test_condaenv_create_with_params(
207201
make_conda: Callable[..., tuple[CondaEnv, Path]],
208202
) -> None:
@@ -216,7 +210,6 @@ def test_condaenv_create_with_params(
216210
assert dir_.joinpath("bin", "pip").exists()
217211

218212

219-
@has_conda
220213
def test_condaenv_create_interpreter(
221214
make_conda: Callable[..., tuple[CondaEnv, Path]],
222215
) -> None:
@@ -232,7 +225,6 @@ def test_condaenv_create_interpreter(
232225
assert dir_.joinpath("bin", "python3.12").exists()
233226

234227

235-
@has_conda
236228
def test_conda_env_create_verbose(
237229
make_conda: Callable[..., tuple[CondaEnv, Path]],
238230
) -> None:
@@ -264,13 +256,11 @@ def test_condaenv_bin_windows(make_conda: Callable[..., tuple[CondaEnv, Path]])
264256
] == venv.bin_paths
265257

266258

267-
@has_conda
268259
def test_condaenv_(make_conda: Callable[..., tuple[CondaEnv, Path]]) -> None:
269260
venv, _dir = make_conda()
270261
assert not venv.is_offline()
271262

272263

273-
@has_conda
274264
def test_condaenv_detection(make_conda: Callable[..., tuple[CondaEnv, Path]]) -> None:
275265
venv, dir_ = make_conda()
276266
venv.create()
@@ -555,7 +545,7 @@ def test_not_stale_virtualenv_environment(
555545
assert reused
556546

557547

558-
@has_conda
548+
@pytest.mark.conda
559549
def test_stale_virtualenv_to_conda_environment(
560550
make_one: Callable[..., tuple[VirtualEnv | ProcessEnv, Path]],
561551
) -> None:
@@ -570,7 +560,7 @@ def test_stale_virtualenv_to_conda_environment(
570560
assert not reused
571561

572562

573-
@has_conda
563+
@pytest.mark.conda
574564
def test_reuse_conda_environment(
575565
make_one: Callable[..., tuple[VirtualEnv | ProcessEnv, Path]],
576566
) -> None:
@@ -586,7 +576,7 @@ def test_reuse_conda_environment(
586576

587577

588578
# This mocks micromamba so that it doesn't need to be installed.
589-
@has_conda
579+
@pytest.mark.conda
590580
def test_micromamba_environment(
591581
make_one: Callable[..., tuple[VirtualEnv | ProcessEnv, Path]],
592582
monkeypatch: pytest.MonkeyPatch,
@@ -611,7 +601,7 @@ def test_micromamba_environment(
611601
"params",
612602
[["--channel=default"], ["-cdefault"], ["-c", "default"], ["--channel", "default"]],
613603
)
614-
@has_conda
604+
@pytest.mark.conda
615605
def test_micromamba_channel_environment(
616606
make_one: Callable[..., tuple[VirtualEnv, Path]],
617607
monkeypatch: pytest.MonkeyPatch,
@@ -642,7 +632,7 @@ def test_micromamba_channel_environment(
642632
("venv", "virtualenv", True),
643633
("virtualenv", "uv", True),
644634
pytest.param("uv", "virtualenv", False, marks=has_uv),
645-
pytest.param("conda", "virtualenv", False, marks=has_conda),
635+
pytest.param("conda", "virtualenv", False, marks=pytest.mark.conda),
646636
],
647637
)
648638
def test_stale_environment(

0 commit comments

Comments
 (0)