<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><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="qt" style=""><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 class="font" style="font-family:monospace;"><span style="color:rgb(0, 0, 0);background-color:rgb(255, 255, 255);--darkreader-inline-color:#dbd8d4;--darkreader-inline-bgcolor:#161819;" data-darkreader-inline-color="" data-darkreader-inline-bgcolor="">QObject::killTimer: Timers cannot be stopped from another thread`,</span></span><br></div><div><span class="font" style="font-family:monospace;">followed by a segmentation fault</span><br></div><div><span class="font" style="font-family:monospace;"></span><br></div><div><span class="font" 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 class="font" style="font-family:monospace;"></span><br></div><div><span class="font" 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 class="font" style="font-family:monospace;"></span><br></div><div><span class="font" style="font-family:monospace;">Any idea why the above happens ?</span><br></div><div><span class="font" style="font-family:monospace;"></span><br></div><div><span class="font" 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 class="qt-gmail_signature_prefix">--</span><br></div><div dir="ltr" class="qt-gmail_signature"><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></body></html>