<div dir="ltr"><div dir="ltr"><div>Thanks Kyle,</div><div><br></div><div>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.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 22, 2023 at 2:10 PM Kyle Altendorf <<a href="mailto:sda@fstab.net">sda@fstab.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg-6412848582410190150"><u></u><div><div>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.<br></div><div><br></div><div>Cheers,<br></div><div>-kyle</div><div><br></div><div>On Fri, Sep 22, 2023, at 12:35, Stefan Seefeld wrote:<br></div><blockquote type="cite" id="m_-6412848582410190150qt"><div dir="ltr"><div>Hello,<br></div><div><br></div><div>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".<br></div><div>Summary: I'm unable to set this up, and it isn't clear why this isn't working.<br></div><div><br></div><div>Details: please consider the attached test file (executed with `pytest -vs qt-minimal-test,py`).<br></div><div><br></div><div>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.<br></div><div><br></div><div>Consider these cases:<br></div><div><br></div><div>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.<br></div><div><br></div><div>1. run the above command, but click the "quit" button immediately. Thus results in the error message `<span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">QObject::killTimer: Timers cannot be stopped from another thread`,</span></span><br></div><div><span style="font-family:monospace">followed by a segmentation fault</span><br></div><div><span style="font-family:monospace"></span><br></div><div><span style="font-family:monospace">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.</span><br></div><div><span style="font-family:monospace"></span><br></div><div><span style="font-family:monospace">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</span><br></div><div><span style="font-family:monospace"></span><br></div><div><span style="font-family:monospace">Any idea why the above happens ?</span><br></div><div><span style="font-family:monospace"></span><br></div><div><span style="font-family:monospace">Many thanks for any help you can offer !</span><br></div><div><br></div><div><br></div><div><div><br></div><div><span>--</span><br></div><div dir="ltr"><div dir="ltr"><div><img src="https://ci3.googleusercontent.com/mail-sig/AIorK4yh4RzsqlxV6irScDGRVZ8a7NRCh_INtpPsAHx2Y8v4Vu3VKsI54RFNs3YRZk_2xTTtMMdSCzdNrf5XRUlmF4BkezmtZv-j5c3A4G0hEA"><br></div><div><pre> ...ich hab' noch einen Koffer in Berlin...
<br></pre></div></div></div></div></div><div><br></div><div><b>Attachments:</b><br></div><ul><li>qt-minimal-test.py<br></li></ul></blockquote><div><br></div></div></div></blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><img src="https://ci3.googleusercontent.com/mail-sig/AIorK4yh4RzsqlxV6irScDGRVZ8a7NRCh_INtpPsAHx2Y8v4Vu3VKsI54RFNs3YRZk_2xTTtMMdSCzdNrf5XRUlmF4BkezmtZv-j5c3A4G0hEA"></div><div><pre> ...ich hab' noch einen Koffer in Berlin...
</pre></div></div></div></div>