Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
stdout capture (capsys) does not seem to work with real-time cli logging #3819
Using the snippet from https://docs.pytest.org/en/latest/capture.html#accessing-captured-output-from-a-test-function, just adding a logging call before the second print:
Investigating (it took a while, I find it rather complex) it seems that the problem is on this part on the logging module:
So, it seems that logging does
When that is the case, logging (in the functions mentioned above) will remove the current
Deactivating the fixture capture, changing the code to this would work in theory:
The first solution I could think about was to add another attribute to CaptureManager to keep track of current item and change the activate/deactivate function to use this attribute whenever the function is called without arguments.
I actually implemented it and it makes the test I posted in the issue body pass, but it could be that a better solution exists, especially concerning tracking the last item in
I will now make a PR so we can discuss better around the code.
Unfortunately some glitches are still present - for instance it was always snapping (consuming) the output whenever we suspended global capture, therefore there was some loss of information along the way.
I have already made some a test case and some changes/refactoring and will create another PR for this.