我正在使用 nose
运行一些系统测试,其中之一是测试(配置)文件是否存在。如果这个文件存在,我想对其运行一些额外的测试。如果没有,我想跳过一堆测试。
如果主要测试通过,使 nose
包含附加测试的最佳方法是什么?
最佳答案
您可以在您的特定 TestCase 的 setUp 方法中使用 skipTest,例如:
import os
from unittest import TestCase
class MyTest(TestCase):
def setUp(self):
if not os.path.exists('configfile'):
return self.skipTest('config file not found')
def test01(self):
# Do something with the file
with open('configfile') as fd:
self.assertEqual(fd.readlines().__len__(), 0)
如果配置文件不存在,测试 test01 将不会运行。
关于python - 如果测试通过,我怎样才能包括额外的测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17812786/