-
-
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
Bugfix/capsys with cli logging #3822
Bugfix/capsys with cli logging #3822
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.
looks good, one minor thing I think :D
src/_pytest/capture.py
Outdated
@contextlib.contextmanager | ||
def disabled(self): | ||
"""Temporarily disables capture while inside the 'with' block.""" | ||
if self._current_item is None: |
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.
can probably combine with the below and do:
if getattr(self._current_item, '_capture_fixture', None) is None:
yield
else:
# use self._current_item._capture_fixture directly
...
src/_pytest/logging.py
Outdated
else: | ||
ctx_manager = _dummy_context_manager() | ||
|
||
with ctx_manager: |
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.
nice, I love me some context managers!
Used your nice tip, also decided to keep saving to a Refactored also considering the previous |
It seems like I could merge but just waiting for a last OK. |
Hi @Sup3rGeo, hold on please, I'm working on this branch with a few minor improvements which I decided to just go ahead with, if you are OK with that. 👍 |
Also change the context-manager to global_and_fixture_disabled to better convey its meaning
Made some tweaks, let me know what you think:
|
That's great @nicoddemus, thanks! Just one little question about the capture - why do we have both a global and a fixture capture? This is related to your last item - will we ever want to disable global capture without disabling also the fixture captures? As at least, as I understand, the fixture capture is also part of the whole capture plugin (and CaptureManager.disable would just mean to disable the capture plugin altogether)? But this is really not very important, I agree with merging the way it is now :) |
The global capture is controlled by the And I agree this code is quite complex. I hope I can find some time in the future to study it and perhaps improve it, as it has grown organically over the years.
That's a fair question, that's why I wrote that disclaimer about this breaking the abstraction of the "disabled" method. Because this is an internal API I think it is OK to break the abstraction and be very explicit at what it does, so the caller is well aware that we are disabling global and fixture capturing with it, and takes that in account correctly. This is somewhat subjective though. |
Thanks for the explanation! It makes sense. So if I understood correctly the purpose of the capsys/etc fixtures is really to steal the capture even from pytest itself. Otherwise we could just have provided tests access to the global capture from a fixture I guess. |
One of the reasons is that you can change capture methods: execute with |
Awesome, thanks @Sup3rGeo! |
Fixes #3819
changelog
folder, with a name like<ISSUE NUMBER>.<TYPE>.rst
. See changelog/README.rst for details.master
branch for bug fixes, documentation updates and trivial changes.features
branch for new features and removals/deprecations.Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:
AUTHORS
in alphabetical order;