3

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?

André Anjos
  • 4,641
  • 2
  • 27
  • 34

1 Answers1

3

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.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
  • Good catch, but somehow this plugin does not work correctly with skipped tests. I'm getting an exception `RuntimeError: Protocol error in master/slave communications`. Have you got an easy fix for that? – André Anjos Jan 16 '13 at 09:27
  • After looking at the module, we have created [a version of the plugin](https://github.com/idiap/bob/blob/master/python/bob/test/insulate.py) that supports skipped tests. This seems to work correctly in our builds. – André Anjos Jan 18 '13 at 15:23