fix(logging): restore logger state in dictConfig test (#27)

This commit is contained in:
Jeff Smith 2026-04-19 11:47:32 -06:00
parent 7340a66988
commit 0b6bc126d7

View file

@ -8,7 +8,7 @@ from decimal import Decimal
import pytest import pytest
from quartermaster import month_service, service from quartermaster import month_service
from quartermaster.logging_config import LOG_CONFIG from quartermaster.logging_config import LOG_CONFIG
from quartermaster.models import Section from quartermaster.models import Section
@ -94,24 +94,16 @@ def test_log_config_loads_via_dictconfig():
from quartermaster.logging_config import LOG_CONFIG from quartermaster.logging_config import LOG_CONFIG
qm = logging.getLogger("quartermaster")
saved_propagate = qm.propagate
saved_handlers = qm.handlers[:]
saved_level = qm.level
try:
logging.config.dictConfig(LOG_CONFIG) logging.config.dictConfig(LOG_CONFIG)
finally:
qm.propagate = saved_propagate
@pytest.fixture(autouse=True) qm.handlers = saved_handlers
def _reset_quartermaster_logger(): qm.level = saved_level
"""Ensure the quartermaster logger propagates to root so caplog can capture records.
logging.config.dictConfig (called in test_log_config_loads_via_dictconfig) sets
propagate=False on the quartermaster logger. caplog injects its handler into the
root logger, so records only reach it when propagation is enabled. This fixture
temporarily re-enables propagation for every test in this module and restores the
original value on teardown.
"""
qm_logger = logging.getLogger("quartermaster")
original_propagate = qm_logger.propagate
qm_logger.propagate = True
yield
qm_logger.propagate = original_propagate
def _make_debt_minimum(db, name="Loan", amount=Decimal("100.00")): def _make_debt_minimum(db, name="Loan", amount=Decimal("100.00")):