-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Create LogCaptureHandler if necessary (closes #6240) #6283
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for your contribution!
Yes, please add a test for this fix, since it will help us to avoid introducing a regression in the future.
src/_pytest/logging.py
Outdated
with catching_logs(self.log_file_handler, level=self.log_file_level): | ||
yield | ||
else: | ||
with catching_logs(self.log_file_handler, level=self.log_file_level): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that catching_logs
implicitly logs to LogCaptureHandler
if self.log_file_hander
is None
. I would suggest to be more explicit and pass
self.log_file_handler if self.log_file_handler else LogCaptureHandler()
as the first arg to catching_logs
.
Then your modification to the catching_logs
ctx can be reverted.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Thisch
IIRC there are other places where using a new / anonymous LogCaptureHandler could be used, therefore I've changed it to handle that for the arg being None here already. (it avoids creating it then in several places etc)
But of couse for this patch alone your suggestion might make sense / seems good probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Thisch, I've updated the PR to follow your suggestion.
src/_pytest/logging.py
Outdated
with catching_logs(self.log_file_handler, level=self.log_file_level): | ||
yield | ||
else: | ||
with catching_logs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Thisch shouldn't we keep the reference to the anonymous capture handler?
if self.log_file_handler is None:
self.log_file_handler = LogCaptureHandler()
with catching_logs(self.log_file_handler, level=self.log_file_level):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS we don't have to. TBH I don't yet understand why this fix fixes the problem in #6240. I'll take a closer look in the following days.
src/_pytest/logging.py
Outdated
with catching_logs(self.log_file_handler, level=self.log_file_level): | ||
yield | ||
else: | ||
with catching_logs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS we don't have to. TBH I don't yet understand why this fix fixes the problem in #6240. I'll take a closer look in the following days.
@Thisch ping |
@felixn please let me know if you'd like me to help you finish this, or rather prefer me to do so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @felixn,
As mentioned here: #6240 (comment), this approach looks good to me, but requires minor changes (and a rebase).
If you're not able to update the PR, let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @felixn! LGTM.
@Thisch, your review on this PR is still pending; what do you think about the latest version? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thx for your contribution @felixn!
#6240
All credit goes to @blueyed in:
#6240 (comment)
Should I add a testcase to test this specific behaviour?