Skip to content

Commit 04c07e3

Browse files
committed
Fixed pre-existing error
1 parent 2b7326e commit 04c07e3

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@
5050
from prometheus_client import CollectorRegistry
5151

5252

53+
@pytest.fixture(autouse=True)
54+
def reset_uvicorn_logger_propagation():
55+
"""Reset uvicorn logger state between tests.
56+
57+
Uvicorn's configure_logging() sets uvicorn.access.propagate=False via its
58+
default LOGGING_CONFIG when a server starts. This leaks into subsequent tests
59+
that assert stdlib loggers propagate to the root handler.
60+
"""
61+
yield
62+
import logging
63+
64+
for name in ("uvicorn.access", "uvicorn.error", "uvicorn"):
65+
lg = logging.getLogger(name)
66+
lg.propagate = True
67+
for h in lg.handlers[:]:
68+
lg.removeHandler(h)
69+
70+
5371
@pytest.fixture(autouse=True)
5472
def reset_sse_starlette_app_status():
5573
"""

0 commit comments

Comments
 (0)