Skip to content

AttributeError: 'NoneType' object has no attribute 'signal_triggered' on teardown #69

Closed
@The-Compiler

Description

@The-Compiler

I have some code which looks like this:

class TestJavascriptEscape:

    def _test_escape(self, text, qtbot, webframe):
        # ...
        with qtbot.waitSignal(webframe.loadFinished, raising=True):
            webframe.setHtml(html_source)
        # ...

    @pytest.mark.parametrize('text', TESTS)
    def test_real_escape(self, webframe, qtbot, text):
        """Test javascript escaping with a real QWebPage."""
        self._test_escape(text, qtbot, webframe)

    @hypothesis.given(hypothesis.strategies.text())
    def test_real_escape_hypothesis(self, webframe, qtbot, text):
        """Test javascript escaping with a real QWebPage and hypothesis."""
        self._test_escape(text, qtbot, webframe)

With these fixtures:

@pytest.fixture(scope='session')
def qnam():
    """Session-wide QNetworkAccessManager."""
    from PyQt5.QtNetwork import QNetworkAccessManager
    nam = QNetworkAccessManager()
    nam.setNetworkAccessible(QNetworkAccessManager.NotAccessible)
    return nam


@pytest.fixture
def webpage(qnam):
    """Get a new QWebPage object."""
    from PyQt5.QtWebKitWidgets import QWebPage

    page = QWebPage()
    page.networkAccessManager().deleteLater()
    page.setNetworkAccessManager(qnam)
    return page


@pytest.fixture
def webframe(webpage):
    """Convenience fixture to get a mainFrame of a QWebPage."""
    return webpage.mainFrame()

When I run this (after adding the qtbot.waitSignal call) on Ubuntu Trusty (and only there!) with PyQt 5.2.1, I get this giant log. The gist of it is this:

==================================== ERRORS ====================================
____ ERROR at teardown of TestJavascriptEscape.test_real_escape_hypothesis _____

self = <_pytest.runner.SetupState object at 0x7f991bf86898>
colitem = <Function 'test_real_escape_hypothesis'>

    def _callfinalizers(self, colitem):
        # [...]

.tox/unittests/lib/python3.4/site-packages/_pytest/runner.py:356: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/unittests/lib/python3.4/site-packages/_pytest/python.py:1868: in finish
    func()
.tox/unittests/lib/python3.4/site-packages/_pytest/python.py:1826: in teardown
    next()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

qapp = <PyQt5.QtWidgets.QApplication object at 0x7f9913d87af8>
request = <SubRequest 'qtbot' for <Function 'test_real_escape_hypothesis'>>

    @pytest.yield_fixture
    def qtbot(qapp, request):
# [...]
E               Failed: Qt exceptions in virtual methods:
E               ________________________________________________________________________________
E                 File "/home/buildbotx/slaves/slave/ubuntu-trusty/build/.tox/unittests/lib/python3.4/site-packages/pytestqt/plugin.py", line 427, in _quit_loop_by_signal
E                   self.signal_triggered = True
E               
E               AttributeError: 'NoneType' object has no attribute 'signal_triggered'
E               ________________________________________________________________________________
E                 File "/home/buildbotx/slaves/slave/ubuntu-trusty/build/.tox/unittests/lib/python3.4/site-packages/pytestqt/plugin.py", line 427, in _quit_loop_by_signal
E                   self.signal_triggered = True
E               
E               AttributeError: 'NoneType' object has no attribute 'signal_triggered'

[repeated... a lot]

Do you have any idea what's happening there 😟? It seems self is None... I've seen this in QObjects which are already deleteLater()'ed, but SignalBlocker isn't one...

I'll try to produce a minimal example later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions