2012-04-25 29 views
2

我在我的python项目中使用noseSuiteSuite单元测试。如果发生错误nosetests重新启动测试

问题是我的项目与第三方沙箱相关联,并通过api进行通信,但有时,错误来自他们身边。所以我试图找到一种方法来重新启动一个测试,如果它由于具体错误而失败。

有没有人已经在TestSuite中完成了这个工作?或有一个想法如何做?

由于

回答

1

1)I常常重试内遥控代码测试,而不是重新运行整个测试。

2)但是,如果你真的想重复失败的所有测试,并用更好的解决方案没有一个人来了,你可以写一个自定义的TestRunner,与API类似

#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) 

如果你不不想捕捉异常,你也可以看到一个测试是否成功testResult.wasSuccessful()

RetryManager只是一种存储库/失败日志。

3)使用pytest,它具有内置的此功能:http://pytest.org/latest/xdist.html#looponfailing