Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

run_tests.py 2.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  1. """Script para ejecutar todos los tests unitarios en el proyecto.
  2. Ejecuta pytest en el directorio tests/ con cobertura y reportes.
  3. Dependencias:
  4. - pytest: Para ejecutar pruebas.
  5. - pytest-cov: Para reportes de cobertura.
  6. - subprocess: Para ejecutar comandos.
  7. - logging: Para registro de eventos.
  8. """
  9. import subprocess
  10. import logging
  11. import os
  12. from pathlib import Path
  13. import glob
  14. # Configura el logger
  15. logging.basicConfig(level=logging.INFO)
  16. logger = logging.getLogger(__name__)
  17. def run_all_tests():
  18. """Ejecuta todos los tests en el directorio tests/ con cobertura."""
  19. # El script está en tests/, así que el directorio tests/ es el padre
  20. tests_dir = Path(__file__).parent
  21. if not tests_dir.is_dir():
  22. logger.error(f"Directorio {tests_dir} no encontrado")
  23. return
  24. # Verifica si hay archivos de prueba
  25. test_files = glob.glob(str(tests_dir / "test_*.py"))
  26. if not test_files:
  27. logger.warning(f"No se encontraron archivos de prueba en {tests_dir}")
  28. return
  29. # Usa el python del entorno virtual
  30. python_path = os.path.join(os.environ.get("VIRTUAL_ENV", ""), "Scripts", "python.exe")
  31. logger.info(f"Ejecutando todos los tests en {tests_dir}...")
  32. try:
  33. result = subprocess.run(
  34. [
  35. python_path, "-m", "pytest",
  36. str(tests_dir),
  37. "-v",
  38. "--cov=src",
  39. "--cov-report=html:coverage_report",
  40. "--cov-report=term",
  41. "--disable-warnings"
  42. ],
  43. check=True,
  44. text=True,
  45. encoding="utf-8"
  46. )
  47. logger.info("Tests completados exitosamente")
  48. logger.debug(result.stdout)
  49. except subprocess.CalledProcessError as e:
  50. logger.error(f"Error al ejecutar tests: {e.stderr}")
  51. raise
  52. except UnicodeDecodeError as e:
  53. logger.error(f"Error de codificación: {e}")
  54. raise
  55. if __name__ == "__main__":
  56. run_all_tests()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...