Skip to content

Commit 2afe225

Browse files
authored
tests: make skips a bit smarter (#929)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent befada1 commit 2afe225

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

tests/test_main.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import contextlib
1818
import os
19+
import shutil
1920
import subprocess
2021
import sys
2122
from importlib import metadata
@@ -527,12 +528,18 @@ def test_main_with_bad_session_names(
527528
assert session in stderr
528529

529530

531+
py39py310 = pytest.mark.skipif(
532+
shutil.which("python3.10") is None or shutil.which("python3.9") is None,
533+
reason="Python 3.9 and 3.10 required",
534+
)
535+
536+
530537
@pytest.mark.parametrize(
531538
("sessions", "expected_order"),
532539
[
533540
(("g", "a", "d"), ("b", "c", "h", "g", "a", "e", "d")),
534-
(("m",), ("k-3.9", "k-3.10", "m")),
535-
(("n",), ("k-3.10", "n")),
541+
pytest.param(("m",), ("k-3.9", "k-3.10", "m"), marks=py39py310),
542+
pytest.param(("n",), ("k-3.10", "n"), marks=py39py310),
536543
(("v",), ("u(django='1.9')", "u(django='2.0')", "v")),
537544
(("w",), ("u(django='1.9')", "u(django='2.0')", "w")),
538545
],
@@ -1022,7 +1029,8 @@ def test_symlink_sym_not(monkeypatch: pytest.MonkeyPatch) -> None:
10221029
assert res.returncode == 1
10231030

10241031

1025-
def test_noxfile_script_mode() -> None:
1032+
def test_noxfile_script_mode(monkeypatch: pytest.MonkeyPatch) -> None:
1033+
monkeypatch.delenv("NOX_SCRIPT_MODE", raising=False)
10261034
job = subprocess.run(
10271035
[
10281036
sys.executable,
@@ -1044,9 +1052,8 @@ def test_noxfile_script_mode() -> None:
10441052
assert "hello_world" in job.stdout
10451053

10461054

1047-
def test_noxfile_no_script_mode() -> None:
1048-
env = os.environ.copy()
1049-
env["NOX_SCRIPT_MODE"] = "none"
1055+
def test_noxfile_no_script_mode(monkeypatch: pytest.MonkeyPatch) -> None:
1056+
monkeypatch.setenv("NOX_SCRIPT_MODE", "none")
10501057
job = subprocess.run(
10511058
[
10521059
sys.executable,
@@ -1057,7 +1064,6 @@ def test_noxfile_no_script_mode() -> None:
10571064
"-s",
10581065
"example",
10591066
],
1060-
env=env,
10611067
check=False,
10621068
capture_output=True,
10631069
text=True,

tests/test_tox_to_nox.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
from __future__ import annotations
1616

1717
import os
18+
import shutil
1819
import sys
1920
import textwrap
2021
from pathlib import Path
2122
from typing import TYPE_CHECKING
2223

2324
import pytest
2425

26+
# Jinja2 might be missing
27+
tox_to_nox = pytest.importorskip("nox.tox_to_nox")
28+
2529
if TYPE_CHECKING:
2630
from collections.abc import Callable
2731

2832

29-
tox_to_nox = pytest.importorskip("nox.tox_to_nox")
33+
pytestmark = pytest.mark.skipif(shutil.which("tox") is None, reason="Tox not available")
3034

3135
PYTHON_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}"
3236
PYTHON_VERSION_NODOT = PYTHON_VERSION.replace(".", "")

0 commit comments

Comments
 (0)