question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
thischcommented, Jul 9, 2018

On Mon, Jul 9, 2018 at 1:14 PM Attila notifications@github.com wrote:

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). Hope this helps.

You can use “'%(asctime)s.%(msecs)03d” in your log_format. HTH ’

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pytest-dev/pytest/issues/3009#issuecomment-403444290, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMm9UUsIciyFPf49FFqpXoUvGxyghSRks5uEzr8gaJpZM4Q5ZTI .

0reactions
attila123commented, Jul 9, 2018

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).

[pytest]
log_cli=true
log_level=NOTSET
log_format = %(asctime)s %(levelname)s (%(threadName)-10s) %(filename)s:%(lineno)d %(message)s
log_date_format = %Y-%m-%d %H:%M:%S

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found