httpx/tests/utils.py
Martijn Pieters 049afe5b25
Typing: enable disallow_incomplete_defs (#2476)
The only places mypy reports issues is in the test suite.
2022-11-30 09:04:54 +00:00

22 lines
502 B
Python

import contextlib
import logging
import os
import typing
from httpx import _utils
@contextlib.contextmanager
def override_log_level(log_level: str) -> typing.Iterator[None]:
os.environ["HTTPX_LOG_LEVEL"] = log_level
# Force a reload on the logging handlers
_utils._LOGGER_INITIALIZED = False
_utils.get_logger("httpx")
try:
yield
finally:
# Reset the logger so we don't have verbose output in all unit tests
logging.getLogger("httpx").handlers = []