-
-
Notifications
You must be signed in to change notification settings - Fork 69
Captured output leaking #113
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
Comments
Thanks @The-Compiler, I will try to see what the problem might be tomorrow. Thanks a lot for the detailed investigation! 😄 |
Any update on this? 😄 Or do you have some idea what I could do as a workaround? I tried adding The only other alternative I can think of is to add my own report section for the output, but that'd probably be non-trivial as currently it's just some fixtures and not a real plugin. |
No yet @The-Compiler, didn't have time take a look yet. Hopefully I will have some time this week! 😅 |
Hmmm I did some investigation now while I waited on Travis... my first impression is that This is how pytest's capture code is configured during tests: @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_setup(self, item):
self.resumecapture()
yield
self.suspendcapture_item(item, "setup")
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item):
self.resumecapture()
self.activate_funcargs(item)
yield
#self.deactivate_funcargs() called from suspendcapture()
self.suspendcapture_item(item, "call")
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_teardown(self, item):
self.resumecapture()
yield
self.suspendcapture_item(item, "teardown") And here's @pytest.mark.hookwrapper
@pytest.mark.tryfirst
def pytest_runtest_setup(item):
"""
Hook called after before test setup starts, to start capturing exceptions
as early as possible.
"""
capture_enabled = _is_exception_capture_enabled(item)
if capture_enabled:
item.qt_exception_capture_manager = _QtExceptionCaptureManager()
item.qt_exception_capture_manager.start()
yield
_process_events()
if capture_enabled:
item.qt_exception_capture_manager.fail_if_exceptions_occurred('SETUP')
@pytest.mark.hookwrapper
@pytest.mark.tryfirst
def pytest_runtest_call(item):
yield
_process_events()
capture_enabled = _is_exception_capture_enabled(item)
if capture_enabled:
item.qt_exception_capture_manager.fail_if_exceptions_occurred('CALL')
@pytest.mark.hookwrapper
@pytest.mark.trylast
def pytest_runtest_teardown(item):
"""
Hook called after each test tear down, to process any pending events and
avoiding leaking events to the next test. Also, if exceptions have
been captured during fixtures teardown, fail the test.
"""
_process_events()
_close_widgets(item)
_process_events()
yield
_process_events()
capture_enabled = _is_exception_capture_enabled(item)
if capture_enabled:
item.qt_exception_capture_manager.fail_if_exceptions_occurred('TEARDOWN')
item.qt_exception_capture_manager.finish() As you can see, because If I remove all |
Hmm, I see... I think I understand the issue now, but I don't know what a good solution would be... I guess we'd need more fine-grained ordering of hooks to solve this properly? Alternatively, maybe pytest's hooks for capturing should be declared |
I'm not sure, I think even in this case pytest's will be called later, because IIRC the plugins with the same ordering are called in FILO ordering, so pytest's hooks would be called last anyway (as they are registered first). I might be wrong, but it may be that |
To get the correct behaviour, we'd like to say "after capturing was set up (and before it's torn down), but before/after everything else", right? But I see how this is difficult to get right... 😟 Maybe I just should look into my own capturing for my test-subprocess usecase to have better control over this, as I can't think of a good general solution. I wonder what others think - @hpk42 @flub @RonnyPfannschmidt? |
When using print and relying on pytest to capture it as stdout, we ran into this pytest/pytest-qt issue: pytest-dev/pytest-qt#113 Now we use our own capturing mechanism instead, which also means we get nicer output. Fixes #1122.
So if you could order your hook like say |
@flub let's see what @nicoddemus says - but if I understand the underlying issue correctly, indeed. |
@flub as far as I understand it, that would fix it. |
I recently updated to pytest 2.8 and noticed I got output which should be captured on stdout.
This is during tests which launch a subprocess via
QProcess
which then does logging on stderr, which is printed during the tests (see testprocess.py / quteprocess.py).I was able to reproduce this with this example:
When running it with pytest 2.7.3:
with 2.8.2:
I bisected this to pytest-dev/pytest@c54afbe ("deprecate and warn about
__multicall__
usage in hooks, refine docs about hook ordering, make hookwrappers respect tryfirst/trylast").I also tried reproducing it without pytest-qt but it only seems to happen with pytest-qt.
I'm guessing the event processing happens after pytest already has lifted the capturing, and that commit changed something about the order things are done?
The text was updated successfully, but these errors were encountered: