Pytest 标记测试用例
场景
只执行符合要求的某一部分用例,可以把项目划分为多个模块,然后制定模块名执行
用法
在测试用例方法上加@pytest.mark.标签名
执行
-m 执行自定义标记的相关用例

import pytest
@pytest.mark.add
def test_add_01():
assert (1+1) == 2
@pytest.mark.add
def test_add_02():
assert (2+2) == 3
@pytest.mark.div
def test_div_01():
assert (2/2) == 1
@pytest.mark.minus
def test_minus():
assert (1-1) == 0
命令行运行:
pytest first_web.py -m "add"
#只会执行test_add_01和test_add_02

浙公网安备 33010602011771号