Écrire
# test_prix.py
import pytest
from prix import prix_ttc
def test_tva_par_defaut():
assert prix_ttc(100) == 120
def test_prix_negatif():
with pytest.raises(ValueError):
prix_ttc(-5)
@pytest.mark.parametrize("ht, ttc", [(0, 0), (10, 12), (99.99, 119.99)])
def test_plusieurs(ht, ttc):
assert prix_ttc(ht) == ttc
Lancer
pip install pytest
python -m pytest -q # tous les tests
python -m pytest -k negatif # filtrer par nom
python -m pytest -x # s'arrêter au premier échecNombres décimaux : pytest.approx(0.3). VS Code : onglet Tests (fiole). Lancer les tests à chaque push : GitHub Actions.