[TIP] aborting tests that take too long
Gary Bernhardt
gary.bernhardt at gmail.com
Thu Nov 10 15:43:55 PST 2011
As a quick and dirty solution, you could start a thread that calls
thread.interrupt_main() after n seconds. You'd need to wire it into
the test case with setup/teardown, but it should do the trick. Code
below ("done" never gets printed).
import sys, time, thread, threading
def kill_main_thread():
time.sleep(1)
thread.interrupt_main()
t = threading.Thread(target=kill_main_thread)
t.start()
t.join()
print "done"
--
Gary
http://destroyallsoftware.com
On Thu, Nov 10, 2011 at 7:28 AM, Mark Sienkiewicz <sienkiew at stsci.edu> wrote:
> I have a general problem with tests that deadlock, go into an infinite loop,
> or otherwise just run for way too long. I need to do something about this
> because it is starting to become a problem in my CI system.
>
> When a test takes too long, I don't just want the test to fail if it takes
> too long -- I want it to be forced to stop running. Is there some way to do
> this in py.test or nose?
>
> Mark S.
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
More information about the testing-in-python
mailing list