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
# 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]
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"
总结