我正在尝试创建一个模拟响应,并希望将response.text设置为某些unicode字符。
以下是代码:
class TestClass(TestCase):
@mock.patch(self, mocked_get)
def test_func(self):
mocked_get.side_effect = self.mocked_get
expected_result = [u'ssemsth']
result = self.api.query(query_params)
self.assertEqual(result, expected_result)
def mocked_get(self, *args, **kwargs):
class MockResponse():
def test_result():
res = Response()
res.message = u'semsmth'
return res
# some testcondition
mock_response = MockResponse()
if self.api.counter == 1:
return mock_response.test_result()
在响应的结果中,我得到[u'']
,一个带有空unicode字符串的列表。我想得到[u'semsmth']
有什么想法?我想我不能设置res.message = u'semsth'
而只是返回它。如何为我发送到调用test_function