pytest
pytest copied to clipboard
Cannot log debug and info from ` pytest_configure` hook
Default level (warning) logs are printed no matter the value provide to --log-cli-level
or --log-level
.
# conftest.py
import logging
import pytest
def pytest_configure(config: pytest.Config):
logger = logging.getLogger(__file__)
logger.info("info")
logger.debug("debug")
logger.warning("warning")
logger.error("error")
logger.critical("critical")
pytest -o log_cli=true -o log_cli_level=INFO -o log_level=INFO
warning
error
critical
======================== test session starts ========================
platform darwin -- Python 3.9.16, pytest-7.4.4, pluggy-1.4.0
rootdir: /home/user/pytest-wont-log
collected 0 items
======================== no tests ran in 0.00s ========================
pip freeze
output
exceptiongroup==1.2.0
iniconfig==2.0.0
packaging==23.2
pluggy==1.4.0
pytest==7.4.4
tomli==2.0.1
The logging handling is mostly intended for tests, not for hooks like pytest_configure
. Depending on what you're doing in the hook you might be able to use another hook which is handled.
This issue is stale because it has been open for 14 days with no activity.
This issue was closed because it has been inactive for 7 days since being marked as stale.