Pytest用例打标签

用例打标签:pytest.mark

1、在pytest.ini文件中markers这个配置项注册标签

# pytest.ini
[pytest]
markers=
    smoke:冒烟测试 #冒号后面是标签的描述,可不填
    huigui:回归测试

在这里插入图片描述
2、①通过pytest.mark.标签名给单个用例加一条或多条标签

import pytest

class TestClass():
    
    @pytest.mark.smoke
    @pytest.mark.huigui
    def test_one(self):
        assert 1 == 1

    @pytest.mark.smoke
    def test_two(self):
        assert 2 == 2

    def test_three(self):
        assert 3 == 3

②pytestmark=[pytest.mark.smoke]给测试类所有的用例添加标签

import pytest

pytestmark = [pytest.mark.huigui]
class TestClass():

    @pytest.mark.smoke
    def test_one(self):
        assert 1 == 1

    @pytest.mark.smoke
    def test_two(self):
        assert 2 == 2

    def test_three(self):
        assert 3 == 3

3、执行用例的时候可以通过pytest -m 标签名去筛选用例执行(或者通过pytest.main([’-m’, ‘标签名’]))

# run.py
import pytest

pytest.main(['-m', 'smoke'])

在这里插入图片描述
扩展:筛选多个标签(and or not)
pytest -m “not smoke”----------运行除了smoke标签的用例
pytest -m “smoke or huigui”-----------运行smoke或者huigui的用例

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值