pytest 命令行参数化
时间: 2023-09-02 20:11:26 浏览: 152
pytest支持通过命令行传递参数来进行参数化。首先需要在conftest.py中添加命令行选项,可以使用pytest_addoption函数来实现。在该函数中,可以通过parser.addoption方法添加参数选项,比如"--cmdopt"。然后,可以在用例中使用fixture来调用cmdopt函数,从命令行传入的参数可以通过该函数获取到。例如:@pytest.fixture(scope='class') def cmdopt(request): return request.config.getoption("--cmdopt")。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Pytest 命令行传参代码示例](https://blog.csdn.net/liuchaoqi06/article/details/121142117)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [pytest中命令行传参,以及三种参数化方式](https://blog.csdn.net/weixin_40274647/article/details/120976782)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文