-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
caplog.clear() removes records but leaves collected .text #3297
Comments
This seems like a nice solution (@Thisch what do you think?). |
I'm for reinitializing the stream, hence not using truncate. See https://stackoverflow.com/questions/4330812/how-do-i-clear-a-stringio-object#4330829 @ankostis If you want to work on this I can unassign myself. (I'll probably not have time to work on it soon) |
I'll give it a try. |
You can take a look at my commit (62b224b) |
Done |
Oups, i see now my changelog change is forbiden. Rewritting history without it. Use this if useful: - Fix ``clear()`` method on ``caplog`` fixture which cleared only the ``records``,
and not the ``text```property. (`#3297
<https://github.com/pytest-dev/pytest/issues/3297>`_) |
Hmm it seems your markup around text has an extra backtick and failed to parse. Also don't need to add the link to #3297 because this is added automatically. I suggested a changelog entry on my review because I did not see your comment here, so feel free to use your initial take instead of mine: Fixed ``clear()`` method on ``caplog`` fixture which cleared only the ``records`` attribute but not the ``text`` property. |
Fix #3297 where caplog.clear() did not clear text, just records
Problem
Currently (see pytest versions below), method
LogCaptureHandler.clear()
removes all records from the handler, but it does not clear the collected text in it's.stream
, leading to contradictory results:pytest/_pytest/logging.py
Lines 240 to 244 in 07e768a
pytest/_pytest/logging.py
Lines 220 to 224 in 07e768a
Example
Suggestion
One can either add this line into
.clear()
:OR add this one, which will work also for clients holding handler's
stream
property:Versions
pip list |grep pytest pytest (3.4.2) pytest-cov (2.5.1) pytest-cover (3.0.0) pytest-coverage (0.0) pytest-mock (1.7.1) pytest-runner (4.0)
The text was updated successfully, but these errors were encountered: