Introduction aux tests en Python
Alexander Levin
Data Scientist
Performance — efficacité avec laquelle un logiciel utilise les ressources du système pour accomplir une tâche.
Test de performance — type de test qui mesure la performance d'un logiciel.
Ressources :
Cas :
Installation :
pip install pytest-benchmark
# Example_1.py
import time
def test_func(benchmark):
benchmark(time.sleep, 1)
Commande CLI :
pytest Example_1.py
Résultats obtenus après l'exécution de la commande CLI :

Pour time.sleep(3) au lieu de time.sleep(1) :

# Example_2.py
import time
def test_func(benchmark):
@benchmark
def sleep_for_1_sec():
time.sleep(1)
Commande CLI :
pytest Example_2.py
pytest-benchmark en :benchmark directement@benchmark comme décorateurIntroduction aux tests en Python