我发现可以将JSON数据应用于方法
json.loads()的输出
get_data():
import unittestimport flaskapiimport requestsimport jsonimport sysclass TestFlaskApiUsingRequests(unittest.TestCase): def test_hello_world(self): response = requests.get('http://localhost:5000') self.assertEqual(response.json(), {'hello': 'world'})class TestFlaskApi(unittest.TestCase): def setUp(self): self.app = flaskapi.app.test_client() def test_hello_world(self): response = self.app.get('/') self.assertEqual( json.loads(response.get_data().depre(sys.getdefaultencoding())), {'hello': 'world'} )if __name__ == "__main__": unittest.main()两项测试均按要求通过:
..----------------------------------------------------------------------Ran 2 tests in 0.019sOK[Finished in 0.3s]



