53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
"""Affichage de la progression des tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
from ..outils import RACINE, progression
|
|
|
|
|
|
def test_progression_durations():
|
|
assert progression.duree(0.04) == "0,0 s"
|
|
assert progression.duree(12.34) == "12,3 s"
|
|
assert progression.duree(65) == "1 min 05 s"
|
|
assert progression.duree(3720) == "1 h 02 min"
|
|
assert progression.pluriel(1, "échec") == "1 échec" and progression.pluriel(3, "réussi") == "3 réussis"
|
|
|
|
|
|
def test_progression_output(pytester):
|
|
pytester.makeconftest(f"import sys; sys.path.insert(0, {str(RACINE / 'tests' / 'outils')!r})\n"
|
|
"import progression\n"
|
|
"from progression import pytest_addoption\n"
|
|
"def pytest_configure(config):\n progression.register(config)\n")
|
|
pytester.makepyfile("""
|
|
import pytest, time
|
|
@pytest.mark.parametrize("i", range(30))
|
|
def test_ok(i):
|
|
pass
|
|
def test_skip():
|
|
pytest.skip("non")
|
|
def test_ko():
|
|
assert False
|
|
def test_lent():
|
|
time.sleep(0.3)
|
|
@pytest.fixture
|
|
def casse():
|
|
raise RuntimeError
|
|
def test_prep(casse):
|
|
pass
|
|
""")
|
|
res = pytester.runpytest("--progression", "0.2", "--progression-tests", "10", "-p", "no:cacheprovider")
|
|
out = res.stdout.str()
|
|
lines = [l for l in out.splitlines() if l.startswith("[")]
|
|
assert "34 tests à exécuter ; une ligne toutes les 0,2 s ou tous les 10 tests" in out
|
|
assert re.match(r"^\[10/34 29,4 %\] écoulé \d+,\d s · reste ~\d+,\d s · 10 réussis$", lines[0])
|
|
assert lines[-1].startswith("[34/34 100,0 %]") and "terminé · 31 réussis, 1 ignoré, 1 échec, 1 erreur" in lines[-1]
|
|
assert "ÉCHEC tests" not in out and re.search(r"^ÉCHEC test_progression_output\.py::test_ko · ", out, re.M)
|
|
assert "ÉCHEC (à la préparation) test_progression_output.py::test_prep" in out
|
|
# ni points ni pourcentages de pytest ; son résumé final reste
|
|
assert not re.search(r"^[.sFE]+\s*(\[\s*\d+%\])?$", out, re.M)
|
|
assert "short test summary info" in out or "FAILURES" in out
|
|
res.assert_outcomes(passed=31, skipped=1, failed=1, errors=1)
|
|
# -v ou --progression=0 : affichage habituel
|
|
assert "à exécuter" not in pytester.runpytest("--progression", "0").stdout.str()
|