Skip to content

Commit 4f5986b

Browse files
chore: Flush logger hanlders at exit
1 parent f230647 commit 4f5986b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: tests/conftest.py

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
"""Test Configuration."""
22

33
from __future__ import annotations
4+
5+
import typing as t
6+
7+
if t.TYPE_CHECKING:
8+
import pytest
9+
10+
11+
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None: # noqa: ARG001
12+
"""Session Finish."""
13+
import logging
14+
15+
loggers: list[logging.Logger] = [
16+
logging.getLogger(),
17+
*list(logging.Logger.manager.loggerDict.values()), # type: ignore[list-item]
18+
]
19+
20+
for logger in loggers:
21+
handlers = getattr(logger, "handlers", [])
22+
for handler in handlers:
23+
logger.removeHandler(handler)

0 commit comments

Comments
 (0)