[英]Is it possible to get py.test to skip a test if it is running under coverage?
I'm adding some performance smoke tests to our test suite, and they fail spectacularly when running py.test with coverage. 我在我们的测试套件中添加了一些性能冒烟测试,并且在运行具有覆盖率的py.test时,它们会以失败告终。 This isn't very surprising, nor an indication of a performance issue (timings under coverage don't relate to anything real..)
这既不是很令人惊讶,也不是性能问题的迹象(涵盖范围内的时间与任何真实情况都没有关系。)
How do I mark (ie. pytest.mark.skipif(..)
) these tests so they're automatically skipped during coverage runs? 如何标记(即
pytest.mark.skipif(..)
)这些测试,以便在覆盖运行期间自动跳过它们?
I'm using PyCharm during development if it is relevant. 如果相关,我会在开发过程中使用PyCharm。
That should be quite doable, using the pytest config
object. 使用pytest
config
对象,这应该是完全可行的。 See the very last example on Skip and xfail : 请参阅关于Skip和xfail的最后一个示例:
@pytest.mark.skipif(not pytest.config.getvalue("db"),
reason="--db was not specified")
def test_function(...):
pass
I imagine what you want is just 我想你想要的只是
@pytest.mark.skipif(pytest.config.getvalue("--cov"),
reason="--cov not compatible with smoke tests")
( ETA: The destination of cov
is actually cov_source
, which is why it didn't recognise cov
. Putting --cov
seems like a safer bet as it matches the option you actually type and doesn't require you to know the code internals.) ( 预计到达时间:
cov
的目的地实际上是cov_source
,这就是为什么它不识别cov
。放--cov
似乎是一个更安全的选择,因为它与您实际键入的选项匹配,并且不需要您知道代码内部。 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.