diff --git a/lang/python/python-pytest/Makefile b/lang/python/python-pytest/Makefile index 8fbabd98f2..02a21f1102 100644 --- a/lang/python/python-pytest/Makefile +++ b/lang/python/python-pytest/Makefile @@ -8,11 +8,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=python-pytest -PKG_VERSION:=7.4.0 +PKG_VERSION:=9.0.2 PKG_RELEASE:=1 PYPI_NAME:=pytest -PKG_HASH:=b4bf8c45bd59934ed84001ad51e11b4ee40d40a1229d2c79f9c592b0a3f6bd8a +PKG_HASH:=75186651a92bd89611d1d9fc20f0b4345fd827c41ccd5c299a868a05d70edf11 PKG_MAINTAINER:=Jan Pavlinec , Alexandru Ardelean PKG_LICENSE:=MIT @@ -34,7 +34,8 @@ define Package/python3-pytest +python3 \ +python3-iniconfig \ +python3-packaging \ - +python3-pluggy + +python3-pluggy \ + +python3-pygments endef define Package/python3-pytest/description diff --git a/lang/python/python-pytest/test.sh b/lang/python/python-pytest/test.sh new file mode 100755 index 0000000000..31b48c347b --- /dev/null +++ b/lang/python/python-pytest/test.sh @@ -0,0 +1,110 @@ +#!/bin/sh + +[ "$1" = python3-pytest ] || exit 0 + +# Verify version +python3 - << EOF +import importlib.metadata, sys +version = importlib.metadata.version("pytest") +if version != "$2": + print("Wrong version: " + version) + sys.exit(1) +EOF +[ $? -eq 0 ] || exit 1 + +# Run pytest against a temporary suite that exercises core features +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT + +cat > "$TMPDIR/test_suite.py" << 'PYEOF' +import pytest + +# --- basic pass/fail --- + +def test_passing(): + assert 1 + 1 == 2 + +# --- pytest.raises --- + +def test_raises(): + with pytest.raises(ZeroDivisionError): + 1 / 0 + +def test_raises_match(): + with pytest.raises(ValueError, match="invalid"): + raise ValueError("invalid literal") + +# --- parametrize --- + +@pytest.mark.parametrize("a,b,expected", [ + (1, 2, 3), + (0, 0, 0), + (-1, 1, 0), +]) +def test_add(a, b, expected): + assert a + b == expected + +# --- fixtures --- + +@pytest.fixture +def sample_list(): + return [1, 2, 3] + +def test_fixture_used(sample_list): + assert len(sample_list) == 3 + assert sum(sample_list) == 6 + +@pytest.fixture +def doubled(sample_list): + return [x * 2 for x in sample_list] + +def test_fixture_chaining(doubled): + assert doubled == [2, 4, 6] + +# --- skip / xfail --- + +@pytest.mark.skip(reason="intentional skip") +def test_skipped(): + assert False # never runs + +@pytest.mark.xfail(reason="expected failure") +def test_xfail(): + assert False + +@pytest.mark.xfail(reason="unexpectedly passes") +def test_xpass(): + assert True + +# --- capsys fixture --- + +def test_capsys(capsys): + print("hello pytest") + out, err = capsys.readouterr() + assert out == "hello pytest\n" + assert err == "" + +# --- tmp_path fixture --- + +def test_tmp_path(tmp_path): + f = tmp_path / "hello.txt" + f.write_text("world") + assert f.read_text() == "world" + +# --- monkeypatch fixture --- + +def get_value(): + return 42 + +def test_monkeypatch(monkeypatch): + import test_suite + monkeypatch.setattr(test_suite, "get_value", lambda: 99) + assert get_value() == 99 + +PYEOF + +# Run pytest: expect all to pass (xpass counts as pass by default) +python3 -m pytest "$TMPDIR/test_suite.py" -v --tb=short 2>&1 +STATUS=$? + +# xpass (test_xpass) causes exit code 0 by default — that's fine +[ $STATUS -eq 0 ] || exit 1