running pyqt app event loop in secondary thread, using (Py)Qt6.5
Stefan Seefeld
stefan at seefeld.name
Fri Sep 22 19:46:33 BST 2023
Thanks Kyle,
yes, I'm aware of all those. Unfortunately none of those are of help. My
goal is really to test a C++ (Qt) application, which I have exposed to
Python. From Python, I can then emulate the environment to which the
application is exposed, and test that the application's state progresses
according to plan. So, the pytest test functions present the environment
scenario, interspersed with some assertions of application state, while the
application's own event loop runs within its own thread.
On Fri, Sep 22, 2023 at 2:10 PM Kyle Altendorf <sda at fstab.net> wrote:
> This is not a direct response to your question, so I'll keep it short, but
> just wanted to make sure you are aware of pytest-qt. Also, async tooling
> like whichever is the current asyncio qt integration, qtreactor (twisted),
> and qtrio (trio) may provide insight into coexisting with qt.
>
> Cheers,
> -kyle
>
> On Fri, Sep 22, 2023, at 12:35, Stefan Seefeld wrote:
>
> Hello,
>
> I'm trying to establish a Python test methodology whereby a QApplication
> is launched (and its event loop executed) in a secondary thread, while the
> primary thread performs some "test scenario".
> Summary: I'm unable to set this up, and it isn't clear why this isn't
> working.
>
> Details: please consider the attached test file (executed with `pytest -vs
> qt-minimal-test,py`).
>
> In this minimal test case, the actual test function body is empty. A
> "fixture" function is used to set up the system, i.e. launch a thread to
> construct the application showing only a "quit" button.
>
> Consider these cases:
>
> 0. run the above command, wait for the test passing being reported on the
> console, then click the "quit" button. This appears to be working as
> expected.
>
> 1. run the above command, but click the "quit" button immediately. Thus
> results in the error message `QObject::killTimer: Timers cannot be
> stopped from another thread`,
> followed by a segmentation fault
>
> 2. rather than just "yielding" to the test function, yield the application
> object (so the test function can interact with it). No matter when you
> click the "quit" button, the result is the same as in 1.
>
> 3. call `h.app.quit()` after he `yield` (i.e. as soon as the test function
> completes). Result: the application becomes unresponsive, but doesn't stop
>
> Any idea why the above happens ?
>
> Many thanks for any help you can offer !
>
>
>
> --
>
> ...ich hab' noch einen Koffer in Berlin...
>
>
> *Attachments:*
>
> - qt-minimal-test.py
>
>
>
--
...ich hab' noch einen Koffer in Berlin...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230922/c440aa0f/attachment.htm>
More information about the PyQt
mailing list