一、原因:没有使用正确的数组或没有使用正确的读取数据的方式
二、因为我在yaml中,传参用的是字典格式
三、但是 @pytest.mark.parametrize("",[ ]),需要传数组
import pytest # 数组的形式 @pytest.mark.parametrize("name,word", [["安琪拉", "火烧屁屁咯"], ["黄忠", "黄忠黄忠黄忠"], ["大乔", "大乔大乔大乔"]]) def test_parametrize_02(name, word): print(f'{name}的台词是{word}') print("我是测试parametrize_02" + name, word) # 元祖的形式 @pytest.mark.parametrize("name,word", [("安琪拉", "火烧屁屁咯"), ("黄忠", "黄忠黄忠黄忠"), ("大乔", "大乔大乔大乔")]) def test_parametrize_02(name, word): print(f'{name}的台词是{word}') print("我是测试parametrize_02" + name, word) # 参数值为字典的形式 @pytest.mark.parametrize("hero", [{"name": "安其拉", "word":"7878787878"}, {"name": "黄忠", "word":"太阳被我射熄火了"}, {"name": "后裔", "word":"come on"}]) def test_parametrize_01(hero): print(hero["name"]) print(hero["word"]) # @pytest.mark.parametrize("name,word", ["安琪拉", "火烧屁屁咯"]) 报错 @pytest.mark.parametrize("name,word", [["安琪拉", "火烧屁屁咯"]]) def test_parametrize_02(name, word): print(f'{name}的台词是{word}')
四、修改yaml传参格式
传参也对应修改一下:params = { "shouji": mobile, "appkey": appkey }
@pytest.mark.parametrize("mobile,appkey", get_data['mobile_belong_post']) def test_mobile_post(mobile, appkey): print("测试手机号归属地post请求") params = { 'shouji': mobile, 'appkey': appkey } url = 'http://api.binstd.com/shouji/query' r = requests.post(url=url, params=params) print(r.json()) print(r.status_code) assert r.status_code == 200 result = r.json() assert result['status'] == 0 assert result['msg'] == 'ok' assert result['result']['shouji'] == '13456755448' assert result['result']['province'] == '浙江' assert result['result']['city'] == '杭州' assert result['result']['company'] == '中国移动' assert result['result']['cardtype'] is None assert result['result']['areacode'] == '0571'
标签:TypeError,word,name,unhashable,assert,parametrize,报错,result,print From: https://www.cnblogs.com/songfeigogogo/p/18395284