前言
pytest-base-url
命令行参数传入
# test_01.py
# coding:utf-8
import requests
def test_01(base_url):
data = {
'city': "上海",
'key': 'xxxxxxxxxx'
}
r = requests.post(base_url, data=data)
result = r.json()['reason']
print(r.json())
assert result == '查询成功!'
pytest -vs --base-url http://apis.juhe.cn/simpleWeather/query test_01.py
文章来源:https://www.toymoban.com/news/detail-610875.html
# coding:utf-8
import pytest
import requests
def test_01(base_url):
data = {
'city': "上海",
'key': 'xxxxxxxxx'
}
r = requests.post(base_url, data=data)
result = r.json()['reason']
print(r.json())
assert result == '查询成功!'
if __name__ == '__main__':
pytest.main(['-vs','--base-url','http://apis.juhe.cn/simpleWeather/query',])
pytest.ini方法
[pytest]
base_url = http://apis.juhe.cn/simpleWeather/query
# coding:utf-8
import pytest
import requests
def test_01(base_url):
data = {
'city': "上海",
'key': 'xxxxxxxx'
}
r = requests.post(base_url, data=data)
result = r.json()['reason']
print(r.json())
assert result == '查询成功!'
pytest_dev.ini
# pytest_dev.ini
[pytest]
addopts = --base-url=https://test.anjing.com
pytest_qa.ini
# pytest_qa.ini
[pytest]
addopts = --base-url=https://qa.anjing.com
# coding:utf-8
def test_home_page(base_url):
print(base_url)
assert base_url == "https://test.anjing.com"
总结
文章来源地址https://www.toymoban.com/news/detail-610875.html
到了这里,关于pytest---环境切换(base-url)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!