pytest-base-url插件之配置可选的项目系统URL

前言

①当我们的自动化代码完成之后,通常期望可以在不同的环境进行测试,此时可以将项目系统的URL单独拿出来,并且可以通过pytest.ini配置文件和支持pytest命令行方式执行。

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

③在测试用例里直接传 base_url 参数,当做fixture函数使用(此时就会调用pytets.ini里面的 base_url 地址或者pytest命令行方式执行时的 base_url 参数)

base_url 是pytest中的内置fixture函数。

⑤参考文档:pytest-base-url · PyPI

环境

①Python 2.7、3.6、PyPy 或 PyPy3

②py.test 2.7 或更新版本

安装

复制代码
pip install pytest-base-url

使用

直接在用例里面使用 base_url 参数,当成一个fixture函数使用

复制代码
# -*- encoding:utf-8 -*-


def test_example(base_url):
    assert base_url == 'http://www.example.com'

①pytest命令行方式不添加 --base-url 参数运行

②pytest命令行方式执行并加上 --base-url 参数

复制代码
pytest -vs --base-url=http://www.example.com

运行结果:

③pytest.ini配置文件中添加 base_url 地址

复制代码
# pytest.ini文件内容
[pytest]
base_url = http://www.example.com

运行结果:(这样在pytest命令行方式执行用例的时候就可以不用带上 --base-url 参数)

这可能是B站最详细的pytest自动化测试框架教程,整整100小时,全程实战!!!

相关推荐
ThreeAu.8 小时前
pytest 实战:用例管理、插件技巧、断言详解
python·单元测试·pytest·测试开发工程师
我的xiaodoujiao15 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 18--测试框架Pytest基础 2--插件和参数化
python·学习·测试工具·pytest
小小测试开发1 天前
pytest 库用法示例:Python 测试框架的高效实践
开发语言·python·pytest
know__ledge1 天前
Pytest+requests进行接口自动化测试8.0(Allure进阶 + 文件上传接口 + 单接口多用例)
pytest
川石课堂软件测试2 天前
CSS中常用的几种定位。
开发语言·css·python·网络协议·http·html·pytest
啊森要自信3 天前
【GUI自动化测试】Python 自动化测试框架 pytest 全面指南:基础语法、核心特性(参数化 / Fixture)及项目实操
开发语言·python·ui·单元测试·pytest
啊森要自信3 天前
【GUI自动化测试】YAML 配置文件应用:从语法解析到 Python 读写
android·python·缓存·pytest·pip·dash
我的xiaodoujiao4 天前
从 0 到 1 搭建完整 Python 语言 Web UI自动化测试学习系列 17--测试框架Pytest基础 1--介绍使用
python·学习·测试工具·pytest
程序员杰哥5 天前
Pytest与Unittest测试框架对比
自动化测试·软件测试·python·测试工具·测试用例·excel·pytest
软件测试小仙女5 天前
Pytest参数化实战:高效测试API接口
软件测试·测试开发·测试工具·pytest·接口测试·api·参数化