具有以下代码:
class TestDatabase(unittest.TestCase):
def test_select(self):
pass
class TestWholeThing(unittest.TestCase):
@staticmethod
def get_name_where_feed_status(feed, status):
blablabla
def test_it(self):
print("I have created file")
if __name__ == '__main__':
print("I have deleted file")
unittest.main()
执行输出为:
I have created file
I have deleted file
test_select (__main__.TestDatabase) ... ok
test_it (__main__.TestWholeThing) ... ok
----------------------------------------------------------------------
Ran 2 tests in 1.417s
OK
如果在unittest.main()方法之后执行了第一个测试,为什么要在删除文件之前创建文件?
@编辑 我已经测试了更多的代码: 我还添加了代码以打印名称:
print(__name__)
它似乎是空的。
我也删除了:
if __name__ == '__main__'
unittest.main()
并且仍然收到“我已创建文件”-为什么?