初始化钩子

介绍

调用插件和conftest.py文件的初始化挂钩。

添加命令行选项

  import pytest


  def pytest_addoption(parser:pytest.Parser):
      parser.addoption("--xxxx",default="xxxx",help="url")


  @pytest.fixture()
  def get_weburl(pytestconfig):
      return pytestconfig.getoption("xxxx")

使用pytest_configure钩子在conftest文件中注册标签

def pytest_configure(config):
    config.addinivalue_line(
        "markers", "p0: 这是一个p0级别的测试用例"
    )

在执行测试结束之前执行改钩子

def pytest_unconfigure():
    print("我是pytest_unconfigure")

注:初始化还有其他钩子 详情见

posted @ 2022-11-16 17:47  zhq9  阅读(13)  评论(0编辑  收藏  举报