在Nose中运行单个测试函数与unittest子类相关联

时间:2013-03-07 21:53:57

标签: python nose

nose发现以test_开头的测试,以及unittest.TestCase的子类。

如果希望运行单个TestCase测试,例如:

# file tests.py
class T(unittest.TestCase):
    def test_something():
        1/0

这可以在命令行中使用:

完成
nosetests tests:T.test_something

我有时更喜欢编写一个简单的函数并跳过所有unittest样板:

def test_something_else():
    assert False

在这种情况下,当nose运行我的所有测试时,测试仍然会运行。但是如何使用(Unix)命令行告诉nose仅运行该测试?

1 个答案:

答案 0 :(得分:3)

那将是:

nosetests tests:test_something_else

另一个提示是使用属性

from nose.plugins.attrib import attr

@attr('now')
def test_something_else():
    pass

要运行标记有该属性的所有测试,请执行:

nosetests -a now

相反,避免运行这些测试:

nosetests -a !now