From 4f5986bd669aaac67e672462286a6ff3868b3c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Tue, 3 Dec 2024 21:15:13 -0600 Subject: [PATCH] chore: Flush logger hanlders at exit --- tests/conftest.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 055aa44..c53a13b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,23 @@ """Test Configuration.""" from __future__ import annotations + +import typing as t + +if t.TYPE_CHECKING: + import pytest + + +def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None: # noqa: ARG001 + """Session Finish.""" + import logging + + loggers: list[logging.Logger] = [ + logging.getLogger(), + *list(logging.Logger.manager.loggerDict.values()), # type: ignore[list-item] + ] + + for logger in loggers: + handlers = getattr(logger, "handlers", []) + for handler in handlers: + logger.removeHandler(handler)