pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Cannot log debug and info from ` pytest_configure` hook

Open aaraney opened this issue 1 year ago • 2 comments

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

aaraney avatar Jan 25 '24 21:01 aaraney

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.

bluetech avatar Jan 27 '24 22:01 bluetech

This issue is stale because it has been open for 14 days with no activity.

github-actions[bot] avatar Feb 11 '24 01:02 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Feb 18 '24 01:02 github-actions[bot]