- 目前我正在为我的烧瓶项目编写一个联合测试。我写了一个函数来测试登录功能。当我运行单元测试时,它显示了一些错误消息。
失败 unit_test.py::TestClass::test_login - AttributeError: 'WrapperTestResponse' 对象没有属性 'text'
2.这是我的单元测试实现代码,我可以成功获取状态码但不能获取文本。我犯了一些错误吗?
import unittest
from app import app
import requests
from flask import request
import json
class TestClass(unittest.TestCase):
def setup_class(self):
app.config['TESTING'] = True
self.app = app.test_client()
def teardown_class(self):
"""Do the testing """
pass
def test_login(self):
response = self.app.get('/login')
print(response)
data = {'username': '123456@qq.com', 'password': '12345678'}
response = app.test_client().post('/login', data=json.dumps(data))
self.assertEqual(response.status_code, 200)
print('--------------')
self.assertEqual(response.text, "Invalid login credentials")