From 5349997586c4c81b5f00bd67d2a59de66bf0a525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Tue, 10 Nov 2026 20:30:08 -0600 Subject: [PATCH] =?UTF-8?q?fix(alembic):=20la=20configuraci=C3=B3n=20del?= =?UTF-8?q?=20logging=20de=20las=20migraciones=20no=20deshabilita=20los=20?= =?UTF-8?q?loggers=20de=20la=20aplicaci=C3=B3n=20(O13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alembic/env.py | 5 ++++- tests/test_logging_alembic.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/test_logging_alembic.py diff --git a/alembic/env.py b/alembic/env.py index 424b90c..eee3cd6 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -13,7 +13,10 @@ from app.models import Base config = context.config if config.config_file_name is not None: - fileConfig(config.config_file_name) + # Sin deshabilitar los loggers que ya existen: si no, una migración dentro de la suite apaga + # los de la aplicación (p. ej. `app.services.alertas`) y las pruebas que leen el log fallan + # según el orden en que corren (backlog O13). + fileConfig(config.config_file_name, disable_existing_loggers=False) # Una URL fijada por código (tests) gana sobre DATABASE_URL del entorno. if not config.get_main_option("sqlalchemy.url"): diff --git a/tests/test_logging_alembic.py b/tests/test_logging_alembic.py new file mode 100644 index 0000000..d6c2f02 --- /dev/null +++ b/tests/test_logging_alembic.py @@ -0,0 +1,26 @@ +"""Correr una migración no apaga los loggers de la aplicación (backlog O13). + +`alembic/env.py` configura el logging con `alembic.ini`; con `disable_existing_loggers=True` (el +valor por omisión de `fileConfig`) deshabilitaba `app.services.alertas`, y la prueba que lee su +advertencia fallaba si corría después de una prueba de migración. +""" + +from __future__ import annotations + +import logging +from pathlib import Path + +from alembic import command +from alembic.config import Config + +RAIZ = Path(__file__).resolve().parents[1] + + +def test_una_migracion_no_deshabilita_los_loggers_de_la_app(tmp_path: Path) -> None: + logger = logging.getLogger("app.services.alertas") + assert not logger.disabled + cfg = Config(str(RAIZ / "alembic.ini")) + cfg.set_main_option("script_location", str(RAIZ / "alembic")) + cfg.set_main_option("sqlalchemy.url", f"sqlite:///{tmp_path / 'logging.db'}") + command.upgrade(cfg, "0001") + assert not logger.disabled