How can I configure pytest to be able to see log messages from logging package?

My app uses logging with various levels (WARN, INFO, DEBUG). And when running tests I want to see the log messages on the Run/Debug console.

I read various posts on how to add “Additional arguments” to pytest, e.g. on a run/debug configuration or the pytest template, or pytest.ini.

First, I dont understand where I need to place pytest.ini. Should I place one in each folder where there are tests, or somewhere else?

Second, some parameters seem to have an impact, some not. E.g. the -s and log level arguments seem to have an impact, but the log format argument not. No timestamp is shown.

-s --log-level=DEBUG --log-cli-level=DEBUG --log-format="%(asctime)s %(levelname)s %(message)s"

PyCharm 2024.2.1 (pro)

Python 3.9

Pytest 8.3.2

0
Hello,
pytest.ini should be located in the directory with your test scripts (presumable ./tests). 
If it doesn't work for you, please create an issue on YouTrack on this matter: https://youtrack.jetbrains.com/newIssue
0

请先登录再写评论。