我創建的設置,其中我像這樣創建文件測試:在測試結束如何在python中完成測試後刪除測試文件?
class TestSomething :
def setUp(self):
# create file
fo = open('some_file_to_test','w')
fo.write('write_something')
fo.close()
def test_something(self):
# call some function to manipulate file
...
# do some assert
...
def test_another_test(self):
# another testing with the same setUp file
...
,無論成功或不,我要的測試文件了,所以 如何刪除文件後,我已完成測試?
我想你的意思是在'setupClass()'中創建文件,並在'tearDownClass()'中刪除它。還有一個類似的'setupModule()'和'tearDownModule()'。 – mhawke 2014-09-02 03:54:00
@mhawke謝謝你指向正確的方向,tearDownClass()就是我正在尋找的 – 2014-09-02 04:00:00
@mhawke:是的,謝謝。錯別字... =) – khampson 2014-09-02 04:21:35