微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

pytestini设置公共base_url地址

当我们希望编写的自动代码可以在不同的部署环境执行,这时我们将base_url单独拿出来,通过配置文件和命令行参数执行。
1、安装pytest-base-url插件
pip install pytest-base-url --index-url https://pypi.douban.com/simple
base_url也是一个fixture,下载这个插件就有了。
 
2、在pytest.ini添加base_url
# 在测试用例里直接传base_url,当做fixture使用(此时就会调用Pytets.ini里面的base_URL地址)
# 执行的时候通过命令行执行:pytest即可。
#pytest.ini
[pytest]
base_url=http://www.example.com


# test_a.py
import requests
base_url='http://example.com/'
def test_url(base_url):
    assert  requests.get(base_url).status_code==200
============
D:\code\py_dev_test\pytest框架\pytest_base\pytest_ini配置>pytest --base-url http://example.com
===================================================== test session starts ======================================================
platform win32 -- Python 3.6.0, pytest-4.5.0, py-1.8.0, pluggy-0.13.1
baseurl: http://example.com
rootdir: D:\code\py_dev_test\pytest框架\pytest_base\pytest_ini配置
plugins: allure-pytest-2.8.6, base-url-1.4.2, html-1.19.0, Metadata-1.8.0
collected 1 item 

在这里插入图片描述

在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐