我可以在unittest断言中将方法作为参数传递吗?

2024-09-30 14:36:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我是unittest新手,我想知道是否有任何方法可以将unittest断言函数中的方法作为参数传递。我想看看API调用是否返回包含单词“code”的JSON对象。如果“code”不在我希望它断言的对象中

我得到以下错误

TypeError: argument of type 'NoneType' is not iterable

因为unittest函数将方法视为非类型值

import unittest
class Testing(unittest.TestCase):

def test_createDepositAddress(self):
        result = client.createDepositAddress({"currencySymbol":"BTC"})
        self.assertIn("code", result)

如何检查调用client.createDepositAddress({“currencySymbol”:“BTC”})返回的JSON对象中是否有“code”

下面是从调用client.createDepositAddress({“currencySymbol”:“BTC”})返回的JSON负载

{
    "code": "CRYPTO_ADDRESS_ALREADY_EXISTS"
}

Tags: 对象方法函数selfclientapijsoncode