针对特定断言结果的Python测试

问题描述 投票:0回答:1

我正在尝试编写Python测试,但其中一部分遇到了麻烦。

logging.info('4. Missing \'type\', should fail')
plus_key = PlusKey(id=self.notification.uuid,
                   value=open('/tmp/consumer_private.pem').read())
self.service.create_service_key(None, None, ServiceAPI.KEY_TYPE_PLUS, plus_key)

create_service_key具有以下检查:

if type == ServiceAPI.KEY_TYPE_PLUS:
    assert plus_key.is_valid, \
        'PlusKey is invalid. All properties are mandatory and must be set'

由于我没有在type中包括plus_key,因此该断言失败。

它应该看起来像这样:

plus_key = PlusKey(id=self.notification.uuid,
                   type=plus,
                   value=open('/tmp/consumer_private.pem').read())

如何在测试中检查该方案?

python testing assert
1个回答
0
投票

您是否尝试过使用python调试器(pdb):

import pdb; pdb.set_trace()

或用:]测试

import logging

try:
    print("All is ok")
except:
    lg.warning("Ow : there is some trouble with... Message : {}".format(e))

让我们了解情况!

© www.soinside.com 2019 - 2024. All rights reserved.