繁体   English   中英

pytest不跳过未标记的测试

[英]pytest not skipping unmarked tests

我们有一个标记的测试,我们希望它不会被执行,因为py.test是用另一个标记调用的,但是该测试正在执行。

例如

@pytest.mark.stress
def test_one(some_fixture):
     pass

@pytest.mark.myplatform
def test_two(some_fixture):
     pass

如果我使用--collectonly -m "myplatform and (not stress) ”作为实验运行pytest, --collectonly -m "myplatform and (not stress)可以解决此问题。 我假设使用夹具会以某种方式改变标记的评估方式,但我们假设使用夹具不会影响使用标记收集测试的方式。 夹具中有代码可以查看标记,但是我们不会以任何方式更改pytest args。 克里斯

尝试使用-k标志,并保持相同的过滤逻辑“ myplatform而不是重音”。

https://pytest.org/en/latest/example/markers.html#using-k-expr-to-select-tests-based-on-their-name

基于标记的测试选择/取消选择将测试运行限制为显式标记的测试。 如果使用--collectonly选项,您将无法识别它(在下面的示例中,始终collected 3 items )。

考虑测试文件test_markers.py

import pytest

@pytest.mark.stress
def test_stress():
     pass

@pytest.mark.myplatform
def test_myplatform():
     pass

def test_unmarked():
     pass

如果要执行“压力”测试,请仅使用( -v表示详细输出)

pytest test_markers.py -v -m stress

您得到以下输出:

collected 3 items

test_markers.py::test_stress PASSED

如果要执行“压力”测试而未标记的测试,请使用:

pytest test_markers.py -v -m "not myplatform"

这将为您提供输出:

collected 3 items

test_markers.py::test_stress PASSED
test_markers.py::test_unmarked PASSED

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM