-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Hello,
Is there any plan to support some kind of wrapper on top of qtbot in order to turn the wait* methods into async methods that could be called from a qtrio test? That would be very useful in my opinion, e.g:
@pytest.mark.trio(run=qtrio.run)
async def test(aqtbot):
w = mywidget()
aqtbot.addWidget(w)
async with aqtbot.waitSignal(w.mysignal):
aqtbot.mouseClick(w, QtCore.Qt.LeftButton)The problem with using the blocking methods directly is that all trio code is blocked while waiting for the corresponding signal. I experimented with it using the following test:
import pytest
import trio
import qtrio
from PyQt5.QtCore import QTimer
@pytest.mark.trio(run=qtrio.run)
async def test(qtbot):
async with trio.open_nursery() as nursery:
timer1 = QTimer()
timer1.setSingleShot(True)
timer1.setInterval(200)
timer2 = QTimer()
timer2.setSingleShot(True)
timer2.setInterval(200)
async def aslot():
await trio.sleep(.2)
timer2.start()
timer1.timeout.connect(
lambda: nursery.start_soon(aslot)
)
with qtbot.wait_signal(timer2.timeout):
timer1.start()
# await trio.sleep(1) # Uncomment to fixThe blocking methods are listed below:
waitwaitActivewaitCallbackwaitExposedwaitForWindowShownwaitSignalwaitSignalswaitUntil
My guess is that there are two ways to approach this:
- Either wrap blocking qtbot calls with some qtrio API, e.g:
await qtrio.run_blocking_call(qtbot.wait, 1000)
- Or re-implement the methods using the
qtrioemission API (e.genter_emissions_channel)
Also, thanks for the library :)
Metadata
Metadata
Assignees
Labels
No labels