如何跳过包含docstring中特定文本的测试?

2024-09-28 19:25:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在每个测试方法的docstring中存储提示,这样testloader就可以根据这些提示包含或排除测试。像这样:

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

然后,testloader将发现包含子字符串“#functional”或其他任何内容的所有测试。在

我尽量避免为此使用decorator,因为我认为使用docstring会更灵活。(也许我错了。)

作为新来的鼻子,我将感谢任何帮助。谢谢!在


Tags: testselfheredefwithlogincodedocstring
2条回答

这个@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

然后可以选择一个或多个值来运行:

^{pr2}$

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

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

因此,测试会被调用:

^{pr2}$

相关问题 更多 >