初始化钩子

初始化钩子

  • 调用插件和conftest.py文件的初始化挂钩,添加命令行选项

    import pytest
    
    
    def pytest_addoption(parser:pytest.Parser):
        parser.addoption("--xxxx",default="xxxx",name="weburl")
    
    
    @pytest.fixture()
    def get_weburl(pytestconfig):
        return pytestconfig.getoption("xxxx")
    
  • 使用pytest_configure钩子在conftest文件中注册标签

    def pytest_configure(config):
        config.addinivalue_line(
            "markers", "env(name): mark test to run only on named environment"
        )
    
  • pytest_unconfigure测试结束的时候执行

    def pytest_unconfigure(config):
      pass
    

更多初始化钩子和详情见

posted @ 2022-11-18 16:34  zhq9  阅读(12)  评论(0编辑  收藏  举报