pytest-配置项目不同环境URL

pytest自动化中,在不同环境进行测试,可以将项目中的url单独抽取出来,通过pytest.ini配置文件实现(类似postman中的"Environments")

使用步骤:

1)安装pytest-base-url插件

pytest-base-url 是一个pytest插件,它通过命令行或配置文件提供可选的基本 URL。

pycharm界面file-settings进行安装,如下图:

2)在pytest.ini配置文件中添加base-url环境

3)在测试用例中使用

在测试用例里直接传 base_url 参数,当做fixture函数使用(会调用pytets.ini里面的 base_url 地址), base_url 是pytest中的内置fixture函数

相关推荐
nbwenren2 天前
2026实测:Gemini 3.1 Pro 从需求文档到 pytest 测试用例一条龙教程
测试用例·pytest
我的xiaodoujiao3 天前
API 接口自动化测试详细图文教程学习系列16--项目实战演练3
python·学习·测试工具·pytest
我的xiaodoujiao3 天前
API 接口自动化测试详细图文教程学习系列15--项目实战演练2
python·学习·测试工具·pytest
技术钱4 天前
PyTest配置与API测试用例
servlet·测试用例·pytest
weixin_419658315 天前
pytest 零基础入门实战指南
python·pycharm·pytest
姚青&8 天前
软件测试基础概念
单元测试·pytest
爆更小哇11 天前
pytest集成Allure报告教程
python·测试工具·pytest·接口测试·allure
gCode Teacher 格码致知12 天前
Python提高:pytest的简单案例-由Deepseek产生
python·pytest
gCode Teacher 格码致知12 天前
Python提高: unittest和 pytest的使用方法-由Deepseek产生
开发语言·python·pytest