本文为霍格沃兹测试开发学社学员学习笔记分享
原文链接:https://ceshiren.com/t/topic/27185

actor 测试工程师 as tester
participant 命令行参数 as command
participant 配置信息 as config
participant 底层代码 as code
autonumber
tester -> command : 通过命令执行测试用例,通过参数指定浏览器: pytest --browser=Chrome
command -> config : 获得配置信息
config -> code: 传给底层代码,使用配置信息
pytest_addoption 添加命令行参数组/命令行参数pytest_configure 解析命令行选项,每个插件都会用到这个hook函数pytest_addoption:
pytest_configure:
web_env = {}
def pytest_addoption(parser: Parser):
hogwarts = parser.getgroup("hogwarts")
hogwarts.addoption("--browser", default='Chrome', dest='browser')
def pytest_configure(config: Config):
browser = config.getoption("--browser", default="Chrome")
print(f"通过命令行获取到的浏览器为{browser}")
web_env["browser"] = browser