I have a script which runs a number of unit tests, but when I hit control c it just exits the particular unit test, not the whole script. Is there any way I can achieve this? This is my code which actually performs the execution of the unit tests.
#bitshift right to obtain correct return value, execution of each test.
returnValue = os.system(path) >> 8
#running total of failures in the program.
failures += returnValue
This is how I call this function and exit the program.
failures = execTests(path, testList)
#exit program with returncode as number of failures
sys.exit(failures)
In fact, this feature is already present in the API. Coming from the The Python Standard Library,25.3. unittest — Unit testing framework here is the relevant excerpt:
-c,--catchControl-C during the test run waits for the current test to end and then reports all the results so far. A second Control-C raises the normal
KeyboardInterruptexception.See Signal Handling for the functions that provide this functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With