首页 > 解决方案 > python根据属性跳过单元测试

问题描述

我们使用 python unittest模块和鼻子进行测试,以从它们各自的优势中受益。Nose 使我们能够使用 跳过命令行上的某些测试nose.plugins.attrib,例如:

import nose.plugins.attrib

@nose.plugins.attrib.attr('slow')
class Testdiskio(unittest.TestCase):
    r'slow running disk intensive tests'

然后从命令行我们使用python setup.py nosetests -A "not slow"来运行我们的快速测试。在这种情况下,我们想要运行所有东西,包括磁盘密集型测试,我们使用:python setup.py nosetests

但是python的unittest没有这样的选择。我们已经尝试调整unittest.skipIf装饰器,但是没有机制可以从命令行传递选项来有条件地测试skipIf.

只是想知道是否有人提出了一种解决方案,可以从命令行选择性地运行/跳过针对 python unittest 模块的测试?

标签: pythonunit-testingnose

解决方案


推荐阅读