我创建的设置,其中我像这样创建文件测试:在测试结束如何在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