Skip to content

Handling of exception during teardown. #65

Description

@The-Compiler

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?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions