testsAndMisc/python_pkg/conftest.py
Krzysztof kuhy Rudnicki 2545d72710 test: achieve 100% branch coverage across all python_pkg packages
- Add comprehensive tests for all packages (3572 tests, 100% branch coverage)
- Split oversized test files to stay under 500-line limit
- Add per-file ruff ignores for test-appropriate suppressions
- Fix _cache_decks.py to properly convert JSON lists to tuples
- Add session-scoped conftest fixture for logging handler cleanup (Python 3.14)
- Update ruff pre-commit hook to v0.15.2
- Add codespell ignore words for test data
- Add generated output files to .gitignore
2026-03-21 17:51:36 +01:00

30 lines
813 B
Python

"""Top-level conftest: clean up logging handlers to avoid bad-FD on exit."""
from __future__ import annotations
import contextlib
import logging
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from collections.abc import Iterator
@pytest.fixture(autouse=True, scope="session")
def _cleanup_logging_handlers_at_end() -> Iterator[None]:
"""Remove all root logging handlers after the test session.
Prevents ``OSError: [Errno 9] Bad file descriptor`` when pre-commit
closes file descriptors before the logging atexit handler runs
(observed on Python 3.14).
"""
yield
root = logging.getLogger()
for handler in root.handlers[:]:
with contextlib.suppress(OSError):
handler.close()
root.removeHandler(handler)
logging.shutdown()