I’m using the python unittest framework to test external equipment. In this particular use case I’d actually like to have python do an endurance test that will take a couple of days. (One test will only take a couple minutes but it will be repeated very often.)
In this scenario I’d like to be able to gracefully stop the testing and either resume or restart it later. I can live with restarting it later, but right now I have no means of a graceful stop.
By graceful stop I envision something like: Upon pressing Ctrl-C, last test is finished and the results are returned.
Is there any built in way to achieve this? If not, how I achieve it otherwise?
I found the solution by taking a much closer look at the unittest documentation:
By calling:
a signal handler for Ctrl-C is installed and all results that do:
will gracefully exit in case of a Ctrl-C. Which is exactly what I needed.