Pytest captures your output and your logging to display it only when your test fails. It's not a bug, it's a feature (although an unwanted one as far as I'm concerned)
You can disable the stdout/stderr capture with `-s` and disable the logs capture with `-p no:logging`. Then you will see the test output and the test logs in real time.
A code example and steps to reproduce would be very helpful in identifying the issue
here is the test code:
I cannot see the print and logger output until the test is over. In practice, I need to see all of them real time
I would say a more proper-ish way would be to log into a file and then tail it. That's what logging is used for, otherwise just use prints.
Hi Andrey,
agree in general with your comment about logging usage, but using logging as if it is print during development is really helpful...
In fact I found out that it's a supported feature by pytest https://docs.pytest.org/en/latest/logging.html#live-logs .
By creating a pytest.ini file with this content:
and adding this parameter
--log-cli-level=10
to pytest run configuration, I got what I wanted :)
> I would say a more proper-ish way would be to log into a file and then tail it
No, it wouldn't
Because logging may be setted up differently in test and production environments
Pytest captures your output and your logging to display it only when your test fails. It's not a bug, it's a feature (although an unwanted one as far as I'm concerned)
You can disable the stdout/stderr capture with `-s` and disable the logs capture with `-p no:logging`. Then you will see the test output and the test logs in real time.
How?
I am trying to avoid running from command line, which is why I am using Pycharm.
How to do this with pycharm?
Also, how to allow all pipes to be dumped to console? I see stderr doesn't work when only the .ini file is added.
Noamzilo You can add `-p no:logging -s` to "Additional Arguments" in your Run Configuration or Run Configuration Template for pytest.