{"action":"created","issue":{"url":"https://api.github.com/repos/pytest-dev/pytest-qt/issues/82","labels_url":"https://api.github.com/repos/pytest-dev/pytest-qt/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/pytest-dev/pytest-qt/issues/82/comments","events_url":"https://api.github.com/repos/pytest-dev/pytest-qt/issues/82/events","html_url":"https://github.com/pytest-dev/pytest-qt/issues/82","id":103757080,"number":82,"title":"New event processing changes behaviour of tests which delete objects","user":{"login":"The-Compiler","id":625793,"avatar_url":"https://avatars.githubusercontent.com/u/625793?v=3","gravatar_id":"","url":"https://api.github.com/users/The-Compiler","html_url":"https://github.com/The-Compiler","followers_url":"https://api.github.com/users/The-Compiler/followers","following_url":"https://api.github.com/users/The-Compiler/following{/other_user}","gists_url":"https://api.github.com/users/The-Compiler/gists{/gist_id}","starred_url":"https://api.github.com/users/The-Compiler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/The-Compiler/subscriptions","organizations_url":"https://api.github.com/users/The-Compiler/orgs","repos_url":"https://api.github.com/users/The-Compiler/repos","events_url":"https://api.github.com/users/The-Compiler/events{/privacy}","received_events_url":"https://api.github.com/users/The-Compiler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-28T17:06:46Z","updated_at":"2015-08-29T12:18:47Z","closed_at":null,"body":"In #79, you switched pytest-qt's `waitSignal` to use busy loops because using `QEventLoop` caused a weird segfault.\r\n\r\nI recently wrote a test which fails with the new way of looping without realizing it.\r\n\r\nThe test is making sure that some function behaves properly if an object is already deleted:\r\n\r\n```python\r\n@pytest.mark.parametrize('delete', [True, False])\r\ndef test_set_register_stylesheet(delete, qtbot, config_stub, caplog):\r\n    config_stub.data = {'fonts': {'foo': 'bar'}, 'colors': {}}\r\n    obj = Obj(\"{{ font['foo'] }}\")\r\n\r\n    with caplog.atLevel(9):  # VDEBUG\r\n        style.set_register_stylesheet(obj)\r\n\r\n    records = caplog.records()\r\n    assert len(records) == 1\r\n    assert records[0].message == 'stylesheet for Obj: font: bar;'\r\n\r\n    assert obj.rendered_stylesheet == 'font: bar;'\r\n\r\n    if delete:\r\n        with qtbot.waitSignal(obj.destroyed):\r\n            obj.deleteLater()\r\n\r\n    config_stub.data = {'fonts': {'foo': 'baz'}, 'colors': {}}\r\n    style.get_stylesheet.cache_clear()\r\n    config_stub.changed.emit('fonts', 'foo')\r\n\r\n    if delete:\r\n        expected = 'font: bar;'\r\n    else:\r\n        expected = 'font: baz;'\r\n    assert obj.rendered_stylesheet == expected\r\n```\r\n\r\nThe code under test:\r\n\r\n```python\r\ndef set_register_stylesheet(obj):\r\n    \"\"\"Set the stylesheet for an object based on it's STYLESHEET attribute.\r\n\r\n    Also, register an update when the config is changed.\r\n\r\n    Args:\r\n        obj: The object to set the stylesheet for and register.\r\n             Must have a STYLESHEET attribute.\r\n    \"\"\"\r\n    qss = get_stylesheet(obj.STYLESHEET)\r\n    log.config.vdebug(\"stylesheet for {}: {}\".format(\r\n        obj.__class__.__name__, qss))\r\n    obj.setStyleSheet(qss)\r\n    objreg.get('config').changed.connect(\r\n        functools.partial(update_stylesheet, obj))\r\n\r\n\r\ndef update_stylesheet(obj):\r\n    \"\"\"Update the stylesheet for obj.\"\"\"\r\n    if not sip.isdeleted(obj):\r\n        obj.setStyleSheet(get_stylesheet(obj.STYLESHEET))\r\n```\r\n\r\nThose tests now fail, presumably because the object never got deleted:\r\n\r\n\r\ntest_set_register_stylesheet[True]:\r\n\r\n```\r\n>       assert obj.rendered_stylesheet == expected\r\nE       assert 'font: baz;' == 'font: bar;'\r\nE         - font: baz;\r\nE         ?         ^\r\nE         + font: bar;\r\nE         ?         ^\r\n```\r\n\r\ntest_set_register_stylesheet[False]:\r\n\r\n```\r\n    @pytest.mark.parametrize('delete', [True, False])\r\n    def test_set_register_stylesheet(delete, qtbot, config_stub, caplog):\r\n        config_stub.data = {'fonts': {'foo': 'bar'}, 'colors': {}}\r\n        obj = Obj(\"{{ font['foo'] }}\")\r\n    \r\n        with caplog.atLevel(9):  # VDEBUG\r\n            style.set_register_stylesheet(obj)\r\n    \r\n        records = caplog.records()\r\n        assert len(records) == 1\r\n>       assert records[0].message == 'stylesheet for Obj: font: bar;'\r\nE       assert 'stylesheet f...j: font: baz;' == 'stylesheet fo...j: font: bar;'\r\nE         - stylesheet for Obj: font: baz;\r\nE         ?                             ^\r\nE         + stylesheet for Obj: font: bar;\r\nE         ?                             ^\r\n```\r\n\r\nHere I can imagine I'm not the only one with such a kind of test...\r\n\r\nI think the best way to implement SignalBlocker would actually be a [QSignalSpy](http://doc.qt.io/qt-5/qsignalspy.html) (which would also make #64 easier) - however it only takes one signal, so `SignalBlocker.connect` and `MultiSignalBlocker` won't work with that...\r\n"},"comment":{"url":"https://api.github.com/repos/pytest-dev/pytest-qt/issues/comments/135980228","html_url":"https://github.com/pytest-dev/pytest-qt/issues/82#issuecomment-135980228","issue_url":"https://api.github.com/repos/pytest-dev/pytest-qt/issues/82","id":135980228,"user":{"login":"nicoddemus","id":1085180,"avatar_url":"https://avatars.githubusercontent.com/u/1085180?v=3","gravatar_id":"","url":"https://api.github.com/users/nicoddemus","html_url":"https://github.com/nicoddemus","followers_url":"https://api.github.com/users/nicoddemus/followers","following_url":"https://api.github.com/users/nicoddemus/following{/other_user}","gists_url":"https://api.github.com/users/nicoddemus/gists{/gist_id}","starred_url":"https://api.github.com/users/nicoddemus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicoddemus/subscriptions","organizations_url":"https://api.github.com/users/nicoddemus/orgs","repos_url":"https://api.github.com/users/nicoddemus/repos","events_url":"https://api.github.com/users/nicoddemus/events{/privacy}","received_events_url":"https://api.github.com/users/nicoddemus/received_events","type":"User","site_admin":false},"created_at":"2015-08-29T12:18:47Z","updated_at":"2015-08-29T12:18:47Z","body":"`QSignalSpy` looks excellent, the only problem is that it doesn't have a `wait` method in Qt4, which limits its usefulness. :neutral_face: \r\n\r\nI guess the simplest way is to just revert to using `QEventLoop` then. I will work on this Tomorrow or Monday. :smile:"}}