Restore soulsync logger state between parallel-imports tests
Importing web_server fires utils.logging_config.setup_logging at module-init, which clears + re-installs handlers on the shared 'soulsync' logger and pins its level to the user's configured value. That mutation leaks across tests in the same pytest process. This file runs alphabetically before test_library_reorganize_orchestrator, so the leak broke test_watchdog_warns_about_stuck_workers downstream — it relies on caplog capturing soulsync.library_reorganize warnings via root-logger propagation, and the reconfigured logger's new handler chain swallowed those records before they reached caplog (caplog.records came back empty even though pytest's live-log capture clearly showed the warning fired). Adds an autouse fixture that snapshots the soulsync logger's handlers, level, and propagate flag before each test in this file and restores them afterwards. Pollution stays scoped to this file. tests/test_tidal_auth_instructions.py also imports web_server but runs alphabetically AFTER test_library_reorganize_orchestrator so it never tripped this — fix is scoped here, not a project-wide conftest, so we don't change behaviour for unrelated test files.
This commit is contained in:
parent
1aa565a330
commit
ab85c45785
1 changed files with 33 additions and 0 deletions
|
|
@ -19,11 +19,44 @@ These tests pin the new behaviour:
|
|||
caller (the test verifies that behaviour through the route).
|
||||
"""
|
||||
|
||||
import logging
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _restore_soulsync_logger_state():
|
||||
"""Snapshot the ``soulsync`` logger config before this file's tests
|
||||
run and restore it afterwards.
|
||||
|
||||
Importing ``web_server`` calls ``utils.logging_config.setup_logging``
|
||||
at module-init time, which clears + re-installs handlers on the
|
||||
``soulsync`` logger and pins its level to whatever the user's
|
||||
config said. That mutation leaks across tests in the same pytest
|
||||
process and broke
|
||||
``test_library_reorganize_orchestrator::test_watchdog_warns_about_stuck_workers``
|
||||
that runs later alphabetically and relies on caplog capturing
|
||||
``soulsync.library_reorganize`` warnings via root-logger
|
||||
propagation.
|
||||
|
||||
Without this fixture, my file ran first alphabetically, mutated
|
||||
the global soulsync logger, and the watchdog test downstream
|
||||
saw ``caplog.records == []``. Snapshot + restore keeps the
|
||||
pollution scoped to this file's tests only.
|
||||
"""
|
||||
soulsync_logger = logging.getLogger("soulsync")
|
||||
saved_handlers = list(soulsync_logger.handlers)
|
||||
saved_level = soulsync_logger.level
|
||||
saved_propagate = soulsync_logger.propagate
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
soulsync_logger.handlers = saved_handlers
|
||||
soulsync_logger.setLevel(saved_level)
|
||||
soulsync_logger.propagate = saved_propagate
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Worker contract
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue