Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protecting nose against Python interpreter crashes

We have a bunch of tests that call Python C/C++ bindings. We run these tests with nose:

nosetests myapp
.....
----------------------------------------------------------------------
Ran 5 tests in 0.009s

Sometimes, it happens that our bindings are buggy, causing the Python interpreter to crash, say, on test number 3:

test03_badcode (myapp.tests.test_badcode) ... Segmentation fault

Question: What is the best way to recover from this? Ideally, I would prefer nose handled these crashes itself, but I understand this is impossible to achieve. The next solution I thought of would be to take note of the test and re-start nose, now skipping the bad test. In my example, this would mean to execute tests 1, 2, 4 and 5, but not test 3. Is there a way to achieve this programatically with nose? Any other better ideas?

like image 565
André Anjos Avatar asked Dec 05 '25 06:12

André Anjos


1 Answers

As usual with nose, there's a plugin for that. Insulate will run each test in a separate process. That will slow things down, but you're guaranteed that a crash in one test won't affect the others.

like image 66
Ned Batchelder Avatar answered Dec 07 '25 21:12

Ned Batchelder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!