Files
needle/tests/test_packaging.py
Ruslan Rakhimov 9bbc9d77af fix(tests): skip the packaging test when tomllib is unavailable (#119)
tomllib is stdlib only from Python 3.11, but pyproject.toml declares
requires-python = ">=3.9". On 3.9 and 3.10 the bare top-level import
raises during collection, which aborts the whole pytest run rather
than failing a single test:

    ImportError while importing test module 'tests/test_packaging.py'
    E   ModuleNotFoundError: No module named 'tomllib'

Use pytest.importorskip so the test degrades to a skip on older
interpreters and still runs unchanged on 3.11+. This keeps the test
dependency-free rather than adding tomli as a backport.
2026-09-12 12:46:14 -07:00

34 lines
1.1 KiB
Python

from __future__ import annotations
from pathlib import Path
import pytest
tomllib = pytest.importorskip("tomllib")
def test_training_dependencies_are_not_required_for_runtime() -> None:
root = Path(__file__).parents[1]
project = tomllib.loads((root / "pyproject.toml").read_text())
runtime = set(project["project"]["dependencies"])
training = set(project["project"]["optional-dependencies"]["train"])
extras = project["project"]["optional-dependencies"]
assert runtime.isdisjoint(training)
assert extras["gpu"]
assert extras["metal"]
assert not set(extras["gpu"]).intersection(training)
assert not set(extras["metal"]).intersection(training)
requirements = {
line.strip()
for line in (root / "requirements.txt").read_text().splitlines()
if line.strip() and not line.startswith("#")
}
train_requirements = {
line.strip()
for line in (root / "requirements-train.txt").read_text().splitlines()
if line.strip() and not line.startswith("#") and not line.startswith("-r ")
}
assert requirements == runtime
assert train_requirements == training