Skip to content

Commit

Permalink
tests: make skips a bit smarter
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Feb 10, 2025
1 parent a74da2c commit c1e1d8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 13 additions & 7 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import contextlib
import os
import shutil
import subprocess
import sys
from importlib import metadata
Expand Down Expand Up @@ -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")),
],
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -1057,7 +1064,6 @@ def test_noxfile_no_script_mode() -> None:
"-s",
"example",
],
env=env,
check=False,
capture_output=True,
text=True,
Expand Down
6 changes: 5 additions & 1 deletion tests/test_tox_to_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@
from __future__ import annotations

import os
import shutil
import sys
import textwrap
from pathlib import Path
from typing import TYPE_CHECKING

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(".", "")
Expand Down

0 comments on commit c1e1d8c

Please sign in to comment.