Skip to content

Plan to support QtAsyncio apps? #599

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

Open
guilbaudl opened this issue Mar 30, 2025 · 3 comments
Open

Plan to support QtAsyncio apps? #599

guilbaudl opened this issue Mar 30, 2025 · 3 comments

Comments

@guilbaudl
Copy link

Hello,
I couldn't find any information regarding QtAsyncio support. Is there any plan moving forward to support apps running thanks to QtAsyncio?

Doc for QtAsyncio

Regards

@nicoddemus
Copy link
Member

Hi @guilbaudl,

No plans so far, in fact I just learned it existed. Seems to be in preview, but definitely seems interesting!

@guilbaudl
Copy link
Author

It is in preview but it is actually part of PySide stable releases, so that would be amazing to try to support it! It is usable so far at least.

@nicoddemus
Copy link
Member

It seems the first steps would be to study what QtAsyncio.run (from the minimal example) does under the covers:

if __name__ == "__main__":
    app = QApplication(sys.argv)
    main_window = MainWindow()
    main_window.show()

    QtAsyncio.run(handle_sigint=True)

I believe it creates the Qt-specific event loop, and integrate with the QApplication somehow... not sure if that is exposed externally or not (could not find with a quick glance at the docs).

Given QtAsyncio still uses a normal QApplication, one does not even need to extend pytest-qt directly, it should be possible to provide your own qapp fixture that setups the asyncio event loop, and the rest of the pytest-qt would still work normally:

# content of conftest.py

@pytest.fixture
def qapp(qapp: QApplication) -> QApplication:
    # The qapp parameter is the builtin pytest-qt `qapp` fixture.
    # At this point, we need to setup the event loop, etc (what QtAsyncio.run does under the covers),
    # but in a non-blocking manner.
    return qapp

Also, we do not need async test functions, because most of the async events would still happen behind sync events.

For example, a test for the MainWindow from that "minimal example" could look like this initially:

def test_main_window(qtbot):
    main_window = MainWindow()
    qtbot.add_widget(main_window)

    main_window.async_trigger.click()  # This triggers the `async set_text` method.

    def check_text_changed():
        assert main_window.text.text() == "What do you get if you multiply six by nine?"

    qtbot.waitUntil(check_text_changed)

Full disclosure, I do not have plans to work on this any time soon, I'm just writing down some quick thoughts in case somebody wants to tackle this.

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