可以通过为用例函数 添加 pytestmarker属性为用例动态添加mark标记,示例如下 import pytest import warnings warnings . filterwarnings ( 'ignore' ) def test_b (): pass def test_a (): pass # 为用例test_a添加一个kk
可以通过为用例函数添加pytestmarker属性为用例动态添加mark标记,示例如下
import pytestimport warnings
warnings.filterwarnings('ignore')
def test_b():
pass
def test_a():
pass
# 为用例test_a添加一个kkk标记
test_a.pytestmark = [
pytest.Mark(name='kkk',args=(), kwargs={})
]
命令行运行
python3 -m pytest -v -m kkk运行结果中可以看到只运行了test_a用例