mirror of
https://github.com/openwrt/packages.git
synced 2026-04-15 19:02:09 +00:00
Changelog since 7.4.0: - v8.1.0: Add namespace packages support; fine-grained verbosity control; improved --import-mode=importlib behavior - v8.2.0: Add command-line argument files via @filename syntax; add PYTEST_VERSION env variable; requires pluggy>=1.5.0 - v8.3.0: Add --xfail-tb flag; marker keyword matching; --no-fold-skipped option; better virtual environment detection - v8.4.0: Async tests without suitable plugin now fail (not warned); tests returning non-None values now fail; drop Python 3.8 support; add pytest.RaisesGroup for ExceptionGroup matching - v9.0.0: Drop Python 3.9 support; subtest support via pytest.Subtests; native TOML config in [tool.pytest] table; strict mode options; PytestRemovedIn9Warning deprecations are now errors - v9.0.1: Restore "raise unittest.SkipTest" support; disable terminal progress for iTerm2 - v9.0.2: Disable terminal progress by default; fix config.inicfg compatibility; fix quadratic-time behavior with unittest subtests Add python3-pygments dependency (new requirement since 8.x). Add test.sh. Full changelog: https://github.com/pytest-dev/pytest/releases Signed-off-by: Alexandru Ardelean <alex@shruggie.ro>
111 lines
2.2 KiB
Bash
Executable File
111 lines
2.2 KiB
Bash
Executable File
#!/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
|