Products
GG网络技术分享 2025-11-10 22:56 2
根据上文的内容,
need_test 的用例:
bash
pytest -m need_test
slow 的用例:
bash
pytest -m slow
need_test 和 slow 的用例:
bash
pytest -m "need_test and slow"
need_test 或 slow 的用例:
bash
pytest -m "need_test or slow"
need_test 的用例:
bash
pytest -m "not need_test"
bash
pytest -m "need_test and "
pytest.ini 配置文件中设置全局标记:
ini
markers =
need_test: test need to run
slow: test is slow
在测试文件中设置局部标记: python import pytest

@pytest.mark.needtest def testlogin: assert login
@pytest.mark.slow def testbuygoods: assert buy_goods
@pytest.mark.dependency @pytest.mark.slow def testaddcart: assert add_cart
bash
pytest -m need_test
在 conftest.py 文件中定义局部标记:
python
import pytest
def pytestcollectionmodifyitems: for item in items: if 'addcart' in item.nodeid: item.addmarker
slow 的用例:
bash
pytest -m "slow"
用例,搞优良测试效率和质量。
Demand feedback