I'm developing a GUI test library of sorts using PySide and Qt. So far it works quite nicely when the test case requires waiting for only one condition to happen (such as a signal or a timeout), but my problem is having to wait for multiple conditions to happen before proceeding with data verification.
The test runner works in its own thread so as not to disturb the main thread too much. Waiting for signals/timeouts happens with an event loop, and this is the part that works nicely (simplified example):
# Create a simple event loop and fail timer (to prevent infinite waiting)
loop = QtCore.QEventLoop()
failtimer = QtCore.QTimer()
failtimer.setInterval(MAX_DELAY)
failtimer.setSingleShot(True)
failtimer.timeout.connect(loop.quit)
# Connect waitable signal to event loop
condition.connect(loop.quit) # condition is for example QLineEdit.textChanged() signal
# Perform test action
testwidget.doStuff.emit() # Function not called directly, but via signals
# Wait for condition, or fail timeout, to happen
loop.exec_()
# Verify data
assert expectedvalue == testwidget.readValue()
The waiting has to be synchronous, so an event loop is the way to go, but it does not work for multiple signals. Waiting for any of multiple conditions is of course possible, but not waiting for multiple conditions/signals to all have happened. So any advice on how to proceed with this?
I was thinking about a helper class that counts the number of signals received and then emits a ready()-signal once the required count is reached. But is this really the best way to go? The helper would also have to check each sender so that only one 'instance' of a specific signal is accounted for.