-
Notifications
You must be signed in to change notification settings - Fork 4
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
Async support for qtbot #250
Comments
Welp, aside from a few people that looked at it in the very early days, you are the first that seems to maybe be using QTrio? Welcome. I have wondered whether it makes sense to provide 'pytest-qt support' or just reimplement the features. I haven't taken the time to look into pytest-qt in detail yet. My impression at this point is that a lot of what it provides is the "async" of the blocking functions you refer to. That when you call them it keeps the Qt loop going for you. This is exactly what QTrio makes available directly with Aside from an implementation of this functionality, with or without pytest-qt, I'm curious to know what situation you are developing in. Do you have tests that need to work with and without QTrio? If compatibility is needed, would a matching API from another library cut it or does it need to be pytest-qt specifically? Without claiming these are solutions, here are the first thoughts of related code that exists and might aid thinking about the topic.
There's my first dump. I'll read through your scenario and see what it looks like. Thanks for checking in. |
Thanks for quick reply!
Right, that makes sense!
We're currently considering a qtrio migration. At the moment we're using separate threads for Qt and each instance of a trio-based user session (the application can host several independent user sessions so it is fine to run each of them in a different trio loop). The communication between threads is done through a job scheduler we developed that lets the qt thread fire jobs that will run within the trio thread and trigger some qt signals when it's done. This works fine but the logic gets quite complicated to maintain when the workflow goes back and forth between qt and trio (error handling is especially tricky). Instead, qtrio would simply let us call some qt within a trio coroutine, and we could rely on standard python flow control (try-except, etc.). My experimentation with qtrio was almost painless since all that's needed is a re-implementation of the job scheduler on top of a simple trio nursery. Migrating the test suite is bit tougher though since we wrote our own trio/qt test runner and wrapper on top of qtbot. In our case, each test is a trio coroutine that blocks the qt execution until a call to qtbot is performed. Still, the migration should mostly be ok if we replace our current async-wrapper of class AsyncQtBot(pytestqt.qtbot.QtBot):
@asynccontextmanager
async def waitSignal(self, signal, timeout=5000):
with trio.fail_after(timeout):
async with qtrio.wait_signal_context(signal):
yield
Thanks for the reference! I didn't know about |
Well, be wary as it isn't documented and as such isn't super public. Anyways, it sounds like just a similar set of functions would satisfy your needs. Do you want to take a pass at it? It could end up here or in pytest-qt itself perhaps. Kind of depends on what it looks like but I suspect there's various sync code that could be reused, or at least ought to be used for reference. But yeah, big picture, this functionality ought to be easily usable with QTrio. |
Hello,
Is there any plan to support some kind of wrapper on top of
qtbot
in order to turn thewait*
methods into async methods that could be called from a qtrio test? That would be very useful in my opinion, e.g: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:
The blocking methods are listed below:
wait
waitActive
waitCallback
waitExposed
waitForWindowShown
waitSignal
waitSignals
waitUntil
My guess is that there are two ways to approach this:
qtrio
emission API (e.genter_emissions_channel
)Also, thanks for the library :)
The text was updated successfully, but these errors were encountered: