如何在Python上的namedTuple中设置字段值?

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

在我的pytest(python 3.7.4)中,我具有测试方法,该方法定义并设置namedtuple的值。但是,尽管我在代码中设置了值,但实际上看不到该字段中设置的任何值。

def test_TapVisaCardOnTheReader(Process):
    ResponseResults = namedtuple('ResponseResults',['STATUS', 'ISO8583', 'TOKEN', 'ICC_PUBLIC_KEY'])
    ResponseResults('01', True, True, True)
    TapResponseResults=Process.TappingPaymentCardOntheReader(' Visa-Card ')
    assert ((ResponseResults.STATUS == TapResponseResults.STATUS) and (
            ResponseResults.ISO8583 == TapResponseResults.ISO8583) and (
                    ResponseResults.TOKEN == TapResponseResults.TOKEN) and (
                    ResponseResults.ICC_PUBLIC_KEY == TapResponseResults.ICC_PUBLIC_KEY))

请检查下面的调试输出窗口,在该窗口中我没有看到任何设置。

OutputWindow另外我还有一个关于namedtuple字段比较的问题,在我的代码中,我不得不比较namedtuple的每个字段,而没有任何方法可以一次比较namedtuple的所有字段。

python-3.7 namedtuple
1个回答
0
投票

在代码的这一部分中,您创建了ResponseResults对象而不保存它:

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