Pytest:取消选择测试 [英] Pytest: Deselecting tests

查看:39
本文介绍了Pytest:取消选择测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 pytest,可以使用装饰器标记测试

With pytest, one can mark tests using a decorator

@pytest.mark.slow
def some_slow_test():
    pass

然后,从命令行,可以告诉 pytest 跳过标记为slow"的测试

Then, from the command line, one can tell pytest to skip the tests marked "slow"

pytest -k-slow

如果我有一个额外的标签:

If I have an additional tag:

@pytest.mark.long
def some_long_test()
    pass

我希望能够跳过长测试和慢测试.我试过这个:

I would like to be able to skip both long AND slow tests. I've tried this:

pytest -k-slow -k-long

还有这个:

pytest -k-slow,long

两者似乎都不起作用.

在命令行中,我如何告诉 pytest 跳过慢测试和长测试?

At the command line, how do I tell pytest to skip both the slow AND the long tests?

推荐答案

此外,通过最近添加的-m"命令行选项,您应该能够编写:

Additionally, with the recent addition of the "-m" command line option you should be able to write:

py.test -m "not (slow or long)"

IOW,-m"选项接受一个表达式,该表达式可以将标记用作布尔值(如果测试函数上不存在标记,则其值为 False,如果存在,则为 True).

IOW, the "-m" option accepts an expression which can make use of markers as boolean values (if a marker does not exist on a test function it's value is False, if it exists, it is True).

这篇关于Pytest:取消选择测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆