Python 如果测试通过,我如何包括其他测试?

Python 如果测试通过,我如何包括其他测试?,python,unit-testing,nose,system-testing,Python,Unit Testing,Nose,System Testing,我正在使用nose运行一些系统测试,其中之一是测试(配置)文件是否存在。如果这个文件存在,我想对它运行一些额外的测试。如果没有,我想跳过一些测试 如果主测试通过,那么让nose包含附加测试的最佳方法是什么?您可以在特定的测试用例中使用setUp方法中的skipTest,例如: import os from unittest import TestCase class MyTest(TestCase): def setUp(self): if not os.path.ex

我正在使用
nose
运行一些系统测试,其中之一是测试(配置)文件是否存在。如果这个文件存在,我想对它运行一些额外的测试。如果没有,我想跳过一些测试


如果主测试通过,那么让
nose
包含附加测试的最佳方法是什么?

您可以在特定的测试用例中使用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将不会运行。

检查assert语句的返回值并设置条件将是创建装饰器的简单方法,如果配置文件不存在,则调用unittest。skipI相信
SkipTest
是应引发而不是返回的异常。