2012-04-25 80 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

相關問題