requests-fixture/excel传参使用

这篇博客介绍了如何在Python自动化测试中利用`pytest`和`openpyxl`库从Excel文件读取数据,并结合`pytest.mark.parametrize`进行数据驱动测试。首先加载Excel文件,然后处理工作表,去掉第一行数据,最后将数据应用于测试用例。
摘要由CSDN通过智能技术生成

import pytest
import requests

@pytest.fixture
def get_weather():
url = “https://jisutqybmf.market.alicloudapi.com/weather/query”

query = {
    "city": "上海"
}
header = {
    "Authorization": "APPCODE 36a6d64593884af1971d218d14a23f9d"
}
r = requests.get(url=url, params=query, headers=header)
return r.json()

def test_create_topic(get_weather):
result = get_weather[‘result’]

city = result['city']
date = result['date']
week = result['week']
weather = result['weather']
content = f'今天是{date},{week},这里是{city},今天天气{weather}。\n'
index_values = result['index']
for val in index_values:
    content += f'{val["iname"]}-{val["ivalue"]}-{val["detail"]}\n'

print(content)

url = 'http://49.233.108.117:3000/api/v1/topics'
json_data
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值