From c1e1d8cda77a51a67b58ba0ccd8983d027f5de73 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 10 Feb 2025 18:41:47 -0500 Subject: [PATCH] tests: make skips a bit smarter Signed-off-by: Henry Schreiner --- tests/test_main.py | 20 +++++++++++++------- tests/test_tox_to_nox.py | 6 +++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 16258f44..8334167f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -16,6 +16,7 @@ import contextlib import os +import shutil import subprocess import sys from importlib import metadata @@ -527,12 +528,18 @@ def test_main_with_bad_session_names( assert session in stderr +py39py310 = pytest.mark.skipif( + shutil.which("python3.10") is None or shutil.which("python3.9") is None, + reason="Python 3.9 and 3.10 required", +) + + @pytest.mark.parametrize( ("sessions", "expected_order"), [ (("g", "a", "d"), ("b", "c", "h", "g", "a", "e", "d")), - (("m",), ("k-3.9", "k-3.10", "m")), - (("n",), ("k-3.10", "n")), + pytest.param(("m",), ("k-3.9", "k-3.10", "m"), marks=py39py310), + pytest.param(("n",), ("k-3.10", "n"), marks=py39py310), (("v",), ("u(django='1.9')", "u(django='2.0')", "v")), (("w",), ("u(django='1.9')", "u(django='2.0')", "w")), ], @@ -1022,7 +1029,8 @@ def test_symlink_sym_not(monkeypatch: pytest.MonkeyPatch) -> None: assert res.returncode == 1 -def test_noxfile_script_mode() -> None: +def test_noxfile_script_mode(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv("NOX_SCRIPT_MODE", raising=False) job = subprocess.run( [ sys.executable, @@ -1044,9 +1052,8 @@ def test_noxfile_script_mode() -> None: assert "hello_world" in job.stdout -def test_noxfile_no_script_mode() -> None: - env = os.environ.copy() - env["NOX_SCRIPT_MODE"] = "none" +def test_noxfile_no_script_mode(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("NOX_SCRIPT_MODE", "none") job = subprocess.run( [ sys.executable, @@ -1057,7 +1064,6 @@ def test_noxfile_no_script_mode() -> None: "-s", "example", ], - env=env, check=False, capture_output=True, text=True, diff --git a/tests/test_tox_to_nox.py b/tests/test_tox_to_nox.py index 17751466..6a3498cb 100644 --- a/tests/test_tox_to_nox.py +++ b/tests/test_tox_to_nox.py @@ -15,6 +15,7 @@ from __future__ import annotations import os +import shutil import sys import textwrap from pathlib import Path @@ -22,11 +23,14 @@ import pytest +# Jinja2 might be missing +tox_to_nox = pytest.importorskip("nox.tox_to_nox") + if TYPE_CHECKING: from collections.abc import Callable -tox_to_nox = pytest.importorskip("nox.tox_to_nox") +pytestmark = pytest.mark.skipif(shutil.which("tox") is None, reason="Tox not available") PYTHON_VERSION = f"{sys.version_info.major}.{sys.version_info.minor}" PYTHON_VERSION_NODOT = PYTHON_VERSION.replace(".", "")