httpx/tests/utils.py
Tom Christie 9c7c2ace99
Add httpx.MockTransport() (#1401)
* Add httpx.MockTransport

* Add docs on MockTransport

* Add pointer to RESPX

* Add note on pytest-httpx

* Tweak existing docs example to use 'httpx.MockTransport'

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
2021-01-06 11:04:26 +00:00

21 lines
463 B
Python

import contextlib
import logging
import os
from httpx import _utils
@contextlib.contextmanager
def override_log_level(log_level: str):
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 = []