如何跳过其docstring中包含某些文本的测试



我想将提示存储在每个测试方法的DocString中,因此Testloader可以根据这些提示包括或排除测试。这样的东西:

def test_login_with_valid_credentials(self):
    '''#functional #security #nondestructive'''
    # code goes here

然后,测试负载器将发现所有包含substring"#functunctional"或其他的测试。

我正在努力避免为此目的使用装饰器,因为我认为使用Docstrings会更灵活。(也许我错了。)

是新手的鼻子,感谢任何帮助。谢谢!

@attr鼻子装饰器不是为此而来吗?https://nose.readthedocs.org/en/latest/plugins/attrib.html

from nose.plugins.attrib import attr
@attr(tags=['b','c'])
def test_bc():
    print 1
@attr(tags=['a','b'])
def test_ab():
    print 1
@attr(tags=['a'])
def test_a():
    print 1

然后您可以选择一个或几个值以进行运行:

> nosetests -v -a tags=b  test.py         
test.test_bc ... ok
test.test_ab ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.001s
> nosetests -v -a tags=b -a tags=a test.py
test.test_bc ... ok
test.test_ab ... ok
test.test_a ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.002s

如果有人想知道,这是实际语法:

@attr(functional=True, security=True, nondestructive=False)

因此调用了测试:

/usr/local/bin/nosetests -v --exe -a functional -w test_directory

最新更新