Incorporating data acquisition in python automated test

Hi all,

I am writing an automated workflow test that is supposed to collect some data at times. This would mean that at certain points in the test, I “let it run” until it collects a certain seconds of replayed tracked ultrasound data.

The problem I’m facing is that an automated test is deemed finished when its main function returns, but I need to incorporate some idle run, which cannot be done using time.sleep because then the event queue is stopped. So I’d need to wait in some way that does not release execution from the main runTest function. I have a few ideas, but each have some problems:

  • Wait using singleShot: Call the function that runs the continuation of the test using QTimer.singleShot. For example runTest calls testWorkflow1 that runs the first part of the test, then when it needs to collect data, then calls testWorkflow2 using singleShot, which then continues the test. In this way I can implement the whole test case, but the automated test is considered done when testWorkflow1 returns after calling singleShot. So errors are not caught during the test run.
  • Implement threading: Start a new thread from runTest that executes the workflow using the above singleShot method, and then at the end sets a variable, for which a while loop waits in runTest. The problem is that the thread needs to access and manipulate lots of things in the application, so it is not safe. I don’t have lots of threading experience, however, so I’m not sure if it could be made safe in some way.

Can anyone think of a solution for this?

Thank you!

Hi Csaba -

It should work to use slicer.util.delayDisplay(message,msec=1000) in a loop in your test. It uses a dialog so that the singleShot happens within the calling context.

-Steve

1 Like

That’s right, the dialog should do the trick. What a simple solution! I’ll try this, thanks a lot!

Update: Works like a charm!