python程序运行报ValueError: {……} is not in list到底什么原因?(已解决)

母函数如下:

 def compareresult(self, data_source, oldresponse, newresponse, comparefield, addfield, wb):
        # newresponse['code'] = 1
        if oldresponse['code'] == 0 and newresponse['code'] == 0:
            if oldresponse['msg'] == 'ok' and newresponse['msg'] == 'ok':
                GetMterials(). comstockcompare(data_source, oldresponse, newresponse, comparefield, addfield, wb)
            elif '个非法' in oldresponse['msg'] and '个非法' in newresponse['msg']:
                self.oldfailnum = re.findall('\d+', oldresponse['msg'])[0]
                self.oldsuccessnum = len(data_source['stock_id'].split(',')) - int(self.oldfailnum)
                print('')
                print('基线版本:本案例共有' + str(int(self.oldfailnum) + int(self.oldsuccessnum)) + '个股票代码,其中' + str(self.oldsuccessnum) + '个合法,' + str(self.oldfailnum) + '个非法')
                print(oldresponse['msg'])
                self.newfailnum = re.findall('\d+', newresponse['msg'])[0]
                self.newsuccessnum = len(data_source['stock_id'].split(',')) - int(self.newfailnum)
                print('待测版本:本案例共有' + str(int(self.newfailnum) + int(self.newsuccessnum)) + '个股票代码,其中' + str(self.oldsuccessnum) + '个合法,' + str(self.newfailnum) + '个非法')
                print(oldresponse['msg'])
                if self.oldsuccessnum == self.newsuccessnum:
                    GetMterials().comstockcompare(data_source, oldresponse, newresponse, comparefield, addfield, wb)
                else:
                    pass
        elif oldresponse['code'] != 0:
            raise Exception('基线版本接口返回异常,stock_id为:' + data_source['stock_id'])
        else:
            raise Exception('待测版本接口返回异常,stock_id为:' + data_source['stock_id'])

子函数如下:

    def comstockcompare(self, data_source, oldresponse, newresponse, comparefield, addfield, wb):
        oldlist = oldresponse['data']
        newlist = newresponse['data']
        newlist[1]['stock_id'] = 'aaaa'
        if isinstance(oldlist, list) and isinstance(newlist, list):
            for i in oldlist:
                signnum = 0  ###i用来做判断两个stock_id是否匹配
                for j in newlist:
                    if i['stock_id'] == j['stock_id']:
                        signnum = 1
                        logicresult = GetMterials().stockcompare(data_source, i, j, comparefield, addfield, wb, oldlist.index(i))
                        # a = 1
                if signnum == 0:
                    logicresult = GetMterials().oldextra(data_source, i, comparefield, addfield, wb, oldlist.index(i))
            oldstockidlist = []
            for i in oldlist:
                oldstockidlist.append(i['stock_id'])
            newextralist = []  ##把newresponse比oldresponse里多出来的stock_id汇总成一个list
            for i in newlist:
                if i['stock_id'] not in oldstockidlist:
                    newextralist.append(i)
            if len(newextralist) > 0:
                # a=type(newextralist)
                # b=type(newextralist[0])
                # GetMterials().newetra(data_source, newextralist, comparefield, addfield, wb, oldlist.index(i))
                c = oldlist.index(i)
                b = len(newextralist) + 1
                GetMterials().abc(oldlist.index(i))
                pass
        elif isinstance(oldlist, dict) and isinstance(newlist, dict):
            logicresult = GetMterials().stockcompare(oldlist, newlist, comparefield, addfield, wb, 0)
        elif isinstance(oldlist, dict) and isinstance(newlist, list):
            pass
        else:
            pass

为什么直接运行pytest到子函数的“c = oldlist.index(i)”报错ValueError: {……} is not in list。
调试在上句打断点,Step Over后竟然直接跳回母函数了,很奇怪一直找不到原因;

找到原因了,i未定义!!!!
太傻叉了,一点技术含量都木有。。。

你可能感兴趣的:(python)