用python练习封装参数化的用例时,后面出现这个错误:json.decoder.JSONDecodeError: Expecting ',' delimiter: line 36 column 32 (char 658)
代码内容:
# 导包
import json
import unittest
from api.login import LoginAPI
from parameterized import parameterized
def buil_data():
json_file = "../data/login.json"
test_data = []
with open(json_file, encoding="utf-8") as f:
json_data = json.load(f)#调用load方法
for case_data in json_data:
login_data = case_data.get("login_data")
status_code = case_data.get("status_code")
success = case_data.get("success")
code = case_data.get("code")
message = case_data.get("message")
test_data.append((login_data, status_code, success, code, message))
print("test_data = {}".format((login_data, status_code, success, code, message)))
return test_data
class TestLogin(unittest.TestCase):
# 前置处理
def setUp(self):
self.login_api = LoginAPI()
# 后置处理
@parameterized.expand(buil_data())
def test01_login(self,login_data, status_code, success, code, message):
response = self.login_api.login(login_data)
print(response.json())
# 断言
self.assertEqual(status_code, response.status_code)
self.assertEqual(success, response.json().get("success"))
self.assertEqual(code, response.json().get("code"))
self.assertIn(message, response.json().get("message"))
通过查看后续错误提示,应该是缺少了“,"号,但是检查整个代码都没有问题,最后问题原来出在调用的参数里,参数和参数之间没有用”,“,修改之后就解决了