logging not captured with pytest 3.3 and xdist
See original GitHub issue(Moved from pytest-dev/pytest-xdist#256)
Consider this file:
import logging
logger = logging.getLogger(__name__)
def test():
logger.warn('Some warning')
When executing pytest foo.py -n2
, the warning is printed to the console:
============================= test session starts =============================
platform win32 -- Python 3.5.0, pytest-3.3.1, py-1.5.2, pluggy-0.6.0
rootdir: C:\Users\bruno, inifile:
plugins: xdist-1.20.1, forked-0.2
gw0 [1] / gw1 [1]
scheduling tests via LoadScheduling
foo.py 6 WARNING Some warning
. [100%]
========================== 1 passed in 0.65 seconds ===========================
Executing pytest
normally without the -n2
flags then the message is not printed.
Using pytest 3.3.1
and xdist 1.20.1
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Logging within pytest tests - python - Stack Overflow
Since version 3.3, pytest supports live logging, meaning that all the log records ... pytest --capture=no tests/system/test_backoffice.py.
Read more >How to manage logging — pytest documentation
pytest captures log messages of level WARNING or above automatically and displays them in their own section for each failed test in the...
Read more >Testing — transformers 3.3.0 documentation - Hugging Face
pytest -xdist provides a very useful feature of detecting all failed tests, and then waiting for you to modify files and continuously re-rerun...
Read more >pytest Documentation - Read the Docs
By default, pytest will not show test durations that are too small (<0.005s) ... pytest captures log messages of level WARNING or above ......
Read more >653722 – dev-python/pytest-forked-0.2 fails test ...
You need to log in before you can comment on or make changes to this ... [ "no", pytest.mark.xfail("sys", reason="capture cleanup needed"), ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
On Mon, Jul 9, 2018 at 1:14 PM Attila notifications@github.com wrote:
You can use “'%(asctime)s.%(msecs)03d” in your log_format. HTH ’
For new users of pytest (maybe coming here googling why their logs are not displayed when testing): based on https://docs.pytest.org/en/latest/logging.html I made this pytest.ini file, with which pytest will output all log messages (in a nicely formatted way).
BTW if anyone knows how to add millisecs to log_date_format, it would be welcome. %f does not seem to work (using pytest 3.6.3). This does not require any command line option for pytest to work. However I found -v adds some nice green “PASSED” etc. results. Hope this helps.