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

Handling of exception during teardown. #65

Closed
The-Compiler opened this issue Aug 1, 2015 · 1 comment
Closed

Handling of exception during teardown. #65

The-Compiler opened this issue Aug 1, 2015 · 1 comment

Comments

@The-Compiler
Copy link
Member

When doing the test teardown, pytest-qt does this:

@pytest.mark.hookwrapper
def pytest_runtest_teardown():
    """
    Hook called after each test tear down, to process any pending events and
    avoiding leaking events to the next test.
    """
    yield
    app = QApplication.instance()
    if app is not None:
        app.processEvents()

PyQt 5.5 changed its behaviour to call abort() if there is an exception in a Qt virtual method and no sys.excepthook is set.

This means if an exception happens during that part, instead of it being silently swallowed (as it's not handled by pytest-qt anymore), in my testfault I got a failure (without much info if running via tox):

$  tox -e unittests -- tests/misc/test_guiprocess.py
[...]
tests/misc/test_guiprocess.py ......ERROR: InvocationError: '/home/florian/proj/qutebrowser/git/.tox/unittests/bin/python -m py.test --strict -rfEsw tests/misc/test_guiprocess.py'

Fortunately using pytest-faulthandler, -s and -v reveals a bit more:

$ tox -e unittests -- -v -s tests/misc/test_guiprocess.py
[...]
tests/misc/test_guiprocess.py::test_cmd_args PASSEDTraceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/objreg.py", line 188, in _get_window_registry
    return win.registry
AttributeError: 'NoneType' object has no attribute 'registry'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/qutebrowser/misc/guiprocess.py", line 94, in on_error
    self._what, msg), immediately=True)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/message.py", line 121, in error
    _wrapper(win_id, 'error', message, immediately)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/message.py", line 52, in _wrapper
    bridge = _get_bridge(win_id)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/message.py", line 86, in _get_bridge
    return objreg.get('message-bridge', scope='window', window=win_id)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/objreg.py", line 215, in get
    reg = _get_registry(scope, window, tab)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/objreg.py", line 204, in _get_registry
    return _get_window_registry(window)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/utils/objreg.py", line 190, in _get_window_registry
    raise RegistryUnavailableError('window')
qutebrowser.utils.objreg.RegistryUnavailableError: window
Fatal Python error: Aborted

Current thread 0x00007f8e31e78700 (most recent call first):
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/pytestqt/plugin.py", line 592 in pytest_runtest_teardown
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 109 in wrapped_call
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 393 in execute
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 123 in __init__
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 107 in wrapped_call
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 393 in execute
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 528 in _docall
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 521 in __call__
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/runner.py", line 137 in <lambda>
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/runner.py", line 149 in __init__
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/runner.py", line 137 in call_runtest_hook
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/runner.py", line 119 in call_and_report
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/runner.py", line 77 in runtestprotocol
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/runner.py", line 65 in pytest_runtest_protocol
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 394 in execute
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 123 in __init__
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 107 in wrapped_call
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 393 in execute
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 528 in _docall
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 521 in __call__
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/main.py", line 142 in pytest_runtestloop
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 394 in execute
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 528 in _docall
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 521 in __call__
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/main.py", line 122 in _main
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/main.py", line 84 in wrap_session
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/main.py", line 116 in pytest_cmdline_main
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 394 in execute
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 528 in _docall
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/core.py", line 521 in __call__
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/_pytest/config.py", line 41 in main
  File "/home/florian/proj/qutebrowser/git/.tox/unittests/lib/python3.4/site-packages/py/test.py", line 4 in <module>
  File "/usr/lib64/python3.4/runpy.py", line 85 in _run_code
  File "/usr/lib64/python3.4/runpy.py", line 170 in _run_module_as_main

I can't reproduce it in a minimal example, but you can clone qutebrowser and run the commandlines above.

I'll of course now fix the exception, but pytest-qt should have some way to handle them (perhaps by using capture_exceptions() in pytest_runtest_teardown as well?).

@nicoddemus
Copy link
Member

Thanks for the report, Florian! 😄

I don't actually follow PyQt5 releases as I don't use it myself, thanks for the heads up. I did reproduce it and opened a PR with the fix. Could you please check if that works with qutebrowser to make sure I'm not missing anything?

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

No branches or pull requests

2 participants