80 lines
2.4 KiB
Python
Executable File
80 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Script pour exécuter les tests unitaires avec pytest
|
|
Usage: uv run python run_tests.py [options]
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
|
|
def run_tests():
|
|
"""Exécute les tests avec pytest et uv"""
|
|
print("🧪 Exécution des tests unitaires avec pytest...")
|
|
print("=" * 50)
|
|
|
|
# Commande de base pour exécuter les tests
|
|
cmd = ["uv", "run", "pytest", "tests/", "-v", "--tb=short"]
|
|
|
|
# Ajouter la couverture de code si demandé
|
|
if "--coverage" in sys.argv:
|
|
cmd.extend(["--cov=.", "--cov-report=term-missing", "--cov-report=html:htmlcov"])
|
|
print("📊 Génération du rapport de couverture activée")
|
|
|
|
# Mode quiet si demandé
|
|
if "--quiet" in sys.argv:
|
|
cmd = ["uv", "run", "pytest", "tests/", "-q"]
|
|
|
|
# Tests spécifiques si un pattern est fourni
|
|
test_pattern = None
|
|
for arg in sys.argv[1:]:
|
|
if not arg.startswith("--"):
|
|
test_pattern = arg
|
|
cmd.append(f"tests/{test_pattern}")
|
|
break
|
|
|
|
try:
|
|
# Exécuter les tests
|
|
result = subprocess.run(cmd, cwd=os.getcwd())
|
|
|
|
print("\n" + "=" * 50)
|
|
if result.returncode == 0:
|
|
print("✅ Tous les tests sont passés avec succès!")
|
|
else:
|
|
print(f"❌ {result.returncode} test(s) ont échoué")
|
|
|
|
if "--coverage" in sys.argv:
|
|
print("📈 Rapport de couverture généré dans htmlcov/index.html")
|
|
|
|
return result.returncode
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n⚠️ Tests interrompus par l'utilisateur")
|
|
return 1
|
|
except Exception as e:
|
|
print(f"❌ Erreur lors de l'exécution des tests: {e}")
|
|
return 1
|
|
|
|
def show_help():
|
|
"""Affiche l'aide"""
|
|
print("""
|
|
Usage: uv run python run_tests.py [options] [pattern]
|
|
|
|
Options:
|
|
--coverage Génère un rapport de couverture de code
|
|
--quiet Mode silencieux (moins de détails)
|
|
--help Affiche cette aide
|
|
|
|
Exemples:
|
|
uv run python run_tests.py # Tous les tests
|
|
uv run python run_tests.py --coverage # Avec couverture
|
|
uv run python run_tests.py test_models.py # Tests d'un fichier spécifique
|
|
uv run python run_tests.py --quiet # Mode silencieux
|
|
""")
|
|
|
|
if __name__ == "__main__":
|
|
if "--help" in sys.argv:
|
|
show_help()
|
|
sys.exit(0)
|
|
|
|
sys.exit(run_tests()) |