python - 如果测试通过,我怎样才能包括额外的测试?

标签 python unit-testing nose system-testing

我正在使用 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/

相关文章:

python - 如何将 Tensorboard 添加到 Tensorflow 估算器进程

Python 测试多个子类的继承

python - 如何从 "python setup.py test"运行 unittest discover ?

python - 如何从同一 TZ 中的 PostgreSQL 获取时间,该时间最初是在上传到数据库时使用的,而不是 UTC?

python - 完成此代码后,我将得到 “TypeError: ' >' not supported between instances of ' float'和 'str'”。我究竟做错了什么?

C# 反射 : Replace a referenced assembly

unit-testing - 您如何对业务应用程序进行单元测试?

python - nosetest输出中字符 `S`代表什么

python - 如何将 cProfile 与 nosetest --with-profile 一起使用?

python - MATLAB/Octave corr 和 Python numpy.correlate 有什么区别?