Files
descarga_factura_transporte/tests/conftest.py
T

36 lines
1.3 KiB
Python
Raw Normal View History

import os
import pytest
import database_utilities
RAIZ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
FIXTURES = os.path.join(RAIZ, "tests", "fixtures", "correos_prueba")
GOLDEN = os.path.join(RAIZ, "tests", "golden")
@pytest.fixture
def actualizar_golden() -> bool:
"""True si se ejecutó con ``UPDATE_GOLDEN=1`` (regenera los resultados esperados)."""
return os.environ.get("UPDATE_GOLDEN") == "1"
@pytest.fixture(autouse=True)
def base_de_datos_temporal(tmp_path_factory, monkeypatch):
"""
Toda prueba usa una BD SQLite propia: ``DB_NAME`` es relativo al directorio
de trabajo, así que sin esto se escribiría en el ``emails.db`` real.
"""
monkeypatch.setattr(database_utilities, "DB_NAME", str(tmp_path_factory.mktemp("bd") / "emails_prueba.db"))
database_utilities.init_db()
@pytest.fixture(autouse=True)
def entorno_de_notificacion_aislado(monkeypatch):
"""
Los módulos cargan el ``.env`` real al importarse. Las pruebas no deben depender de él:
sin esto, un ``NOTIFICACION_MODO=real`` del .env haría que se probara (y enviara) en modo real.
"""
for variable in ("NOTIFICACION_MODO", "NOTIFICACION_EQUIPO", "NOTIFICACION_CONTACTO", "LOGO_URL"):
monkeypatch.delenv(variable, raising=False)
monkeypatch.setenv("EMAIL", "buzon@aberio.com")