Reputation: 23
I am using the TestSuite of nose for unittesting in my python project.
The issue is that my project is linked with third party sandboxes and communicates with by api but sometimes, errors come from their side. So I am trying to find a way to relaunch a test if it fails because of specifics errors.
Does anybody already done this inside a TestSuite? or have an idea how to do?
Thanks
Upvotes: 2
Views: 269
Reputation: 3218
1) I often retry the remote code within the test, instead of rerunning the whole test.
2) However, if you really want to repeat all tests that failed, and no one comes up with a better solution, you could write a custom testrunner, with api something like
#in unittest.TestCase
retryManager.logFailure(test=self, error)
#where you run tests
for test in retryManager.failedTests
suite = unittest.TestLoader().loadTestsFromTestCase(testclass)
testResult = unittest.TextTestRunner(verbosity=2).run(suite)
If you don't want to catch exceptions you can also see if a test was successful with testResult.wasSuccessful()
RetryManager would simply be a kind of repository/log of failures.
3) Use pytest, it has this functionality builtin: http://pytest.org/latest/xdist.html#looponfailing
Upvotes: 1