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小时,全程实战!!!

相关推荐
莫负初2 小时前
Pytest 使用Pycharm右键直接运行测试脚本正常,控制台命令pytest运行收集不到用例无法正常测试 no tests ran in 0.01s
ide·pycharm·pytest
欲游山河十万里20 小时前
pytest(三)——参数化@pytest.mark.parametrize
pytest
奶茶精Gaaa5 天前
pytest
pytest
霍格沃兹测试开发学社测试人社区7 天前
软件测试学习笔记丨Pytest 学习指南
软件测试·笔记·测试开发·学习·pytest
神即道 道法自然 如来8 天前
测试面试题:pytest断言时,数据是符点类型,如何断言?
pytest
high_tea9 天前
pytest - 多线程提速
python·pytest
傻啦嘿哟10 天前
自动化测试框架集成:将Selenium集成到pytest与unittest中
selenium·测试工具·pytest
一名在八月份找工作的测试员11 天前
自动化学习1:pytest自动化框架的基本用法:注意事项/断言assert/测试结果分析
学习·自动化·pytest
什么时候才能变强12 天前
Pytest-如何将allure报告发布至公司内网
linux·服务器·pytest