Skip to content
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

Create LogCaptureHandler if necessary (closes #6240) #6283

Merged
merged 1 commit into from
May 15, 2020
Merged

Create LogCaptureHandler if necessary (closes #6240) #6283

merged 1 commit into from
May 15, 2020

Conversation

felixn
Copy link

@felixn felixn commented Nov 27, 2019

#6240

All credit goes to @blueyed in:
#6240 (comment)

Should I add a testcase to test this specific behaviour?

Copy link
Contributor

@twmr twmr left a 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.

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):
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Author

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.

with catching_logs(self.log_file_handler, level=self.log_file_level):
yield
else:
with catching_logs(
Copy link
Member

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

Copy link
Contributor

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.

changelog/6240.bugfix.rst Outdated Show resolved Hide resolved
with catching_logs(self.log_file_handler, level=self.log_file_level):
yield
else:
with catching_logs(
Copy link
Contributor

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.

@blueyed
Copy link
Contributor

blueyed commented Jan 14, 2020

@thisch ping

@blueyed
Copy link
Contributor

blueyed commented Jan 23, 2020

@felixn @thisch
Is this stalled?
IIRC I'd go with my initial patch and the test added here.

@blueyed
Copy link
Contributor

blueyed commented Jan 26, 2020

@felixn please let me know if you'd like me to help you finish this, or rather prefer me to do so.

@felixn
Copy link
Author

felixn commented Jan 27, 2020

Both the initial fix (ceaefe1) as well as the second revision (b395f00) are working for me. So either is fine from my point of view. If you want me to, I can revert the second change.

Copy link
Member

@bluetech bluetech left a 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.

changelog/6240.bugfix.rst Outdated Show resolved Hide resolved
src/_pytest/logging.py Outdated Show resolved Hide resolved
testing/test_capture.py Outdated Show resolved Hide resolved
@felixn felixn requested review from bluetech and twmr May 13, 2020 18:42
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @felixn! LGTM.

@bluetech
Copy link
Member

@thisch, your review on this PR is still pending; what do you think about the latest version?

Copy link
Contributor

@twmr twmr left a 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!

@felixn
Copy link
Author

felixn commented May 14, 2020

Thanks for the review and positive feedback, @thisch and @bluetech.
I can't merge since I don't have write access, feel free to pull the trigger!

@bluetech bluetech merged commit f0f552d into pytest-dev:master May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants