pytest -mark标记

作用:

  1. 给测试用例或类打上标签,便于管理和运行测试用例

使用:

  1. 在测试用例/测试类前面加上:@pytest.mark.标签名
  2. 打标记范围:测试用例、测试类、模块文件

一、注册标签

使用之前,先注册标签,个人理解就是先定义标签,如果不进行注册运行时(pytest的高级版本)可能会报警告让你进行注册

注册有以下两种方法:

  • pytest.ini
[pytest]

addopts = -v -p no:warnings -p no:faulthandler
filterwaring =
    ignore:.*U.*mode is deprecared:DeprecationWarning
testpaths = ./test ./

markers =
    smoking :
    high    :
    medium  :
    lower   :
  • conftest.py

          需要多少个标签写多少

def pytest_configure(config):
    config.addinvalue_line("markers","P0"),
    config.addinvalue_line("markers","P1"),
    config.addinvalue_line("markers","reg")

二、使用mark标记

     在类或方法前加上

@pytest.mark.标签名

测试代码:

class Test_mark:

    @pytest.mark.P0
    def test_mark1(self,a=1):
        print(a)

    @pytest.mark.P1
    def test_mark2(self,b=2):
        print(b)

测试结果:

 生成报告

pytest -m P0 --html=Report/repot.html

 

posted @ 2022-03-29 13:30  JJLiu  阅读(35)  评论(0编辑  收藏  举报