pytest系列教程——6、mark被标记测试

当写的用例比较多的的时候,我们需要对测试用例进行模块划分,比如,抽出一部分作为冒烟用例。部分用例只能在安卓系统上运行,部分用例只能在IOS上运行等等
这时候就要用到@pytest.mark的功能,给每条用例打上标签,方便运行

使用案例
import pytest
import sys


class Test_Mark():
    def test_mark_01(self):
        assert(1 == 1)

    @pytest.mark.IOS
    @pytest.mark.smokeTest
    def test_mark_02(self):
        print("run in IOS")

    @pytest.mark.Android
    def test_mark_03(self):
        print("run in Android")

    @pytest.mark.IOS
    def test_mark_04(self):
        print("run in IOS")


if __name__ == '__main__':
    #pytest.main(['MyPytest.py', '-m', 'smokeTest'])
    #pytest.main(['MyPytest.py', '-m', 'IOS'])
    pytest.main(['MyPytest.py', '-m', 'smokeTest and IOS'])

运行结果:
collected 4 items / 3 deselected / 1 selected

collected 4 items / 3 deselected / 1 selected

MyPytest.py .                                                            [100%]

============================== warnings summary ===============================
MyPytest.py:9
MyPytest.py:9: PytestUnknownMarkWarning: Unknown pytest.mark.IOS - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.IOS

MyPytest.py:10
MyPytest.py:10: PytestUnknownMarkWarning: Unknown pytest.mark.smokeTest - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.smokeTest

MyPytest.py:14
MyPytest.py:14: PytestUnknownMarkWarning: Unknown pytest.mark.Android - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.Android

MyPytest.py:18
MyPytest.py:18: PytestUnknownMarkWarning: Unknown pytest.mark.Android - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
@pytest.mark.Android

-- Docs: https://docs.pytest.org/en/stable/warnings.html
================= 1 passed, 3 deselected, 4 warnings in 0.07s =================

***Repl Closed**
解决PytestUnknownMarkWarning的问题
  • 创建一个 pytest.ini 文件(后续详解)
  • 加上自定义 mark,如下

在这里插入图片描述

注意:pytest.ini 需要和运行的测试用例同一个目录,或在根目录下作用于全局

运行参数说明
  • pytest -m “key1 or key2” #运行有key1标识或key2标识用例
  • pytest -m “key1 and key2” #运行有key1和key2标识的用例
  • pytest -m “not key1” #运行除了key1之外的标识的用例
  • pytest -m “key1 and not key2” #运行有key1和没有key2标识的用例
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

软件测试技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值