Skip to content

Clarify documentation around qtbot.waitSignals #559

@gdeane-cri

Description

@gdeane-cri

The current docs (https://pytest-qt.readthedocs.io/en/1.5.0/signals.html ) give some examples like this:

def test_long_computation(qtbot):
    app = Application()

    # Watch for the app.worker.finished signal, then start the worker.
    with qtbot.waitSignal(app.worker.finished, timeout=10000) as blocker:
        blocker.connect(app.worker.failed)  # Can add other signals to blocker
        app.worker.start()
        # Test will block at this point until signal is emitted or
        # 10 seconds has elapsed

    assert blocker.signal_triggered, "process timed-out"
    assert_application_results(app)

Except this does not work for me because Application() and assert_application_results are not defined. But the example reads as if this is a necessary step to verify the signal result. Is there some import required for these to function? Are they obsolete? Or if these are simply an example of how one could assert things on app at that point in the test, consider clarifying the example as written.

How to get the QApplication instance when using qtbot is a bit mysterious in the docs too. It just says you can.
Application appears to be replaceable using from pytestqt.qt_compat import qt_api; Application = qt_api.QtWidgets.QApplication.instance but I have no idea if this is good practice.

Activity

nicoddemus

nicoddemus commented on Jun 4, 2024

@nicoddemus
Member

Or if these are simply an example of how one could assert things on app at that point in the test

Yeah those are meant as examples of that, sorry that is not very clear.

How to get the QApplication instance when using qtbot is a bit mysterious in the docs too. It just says you can.
Application appears to be replaceable using from pytestqt.qt_compat import qt_api; Application = qt_api.QtWidgets.QApplication.instance but I have no idea if this is good practice.

No that Application is not meant to be a QApplication, just as placeholder meaning "your application class" or something like that.

Feel free to open a PR clarifying the docs (or even using a more explicit example if you come up with one), would love to review/merge a PR in that direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nicoddemus@gdeane-cri

        Issue actions

          Clarify documentation around qtbot.waitSignals · Issue #559 · pytest-dev/pytest-qt