关于Pytest进行接口测试时出现“AttributeError: module ‘trafaret‘ has no attribute ‘StrBool‘”错误的解决办法

关于Pytest进行接口测试时出现“AttributeError: module ‘trafaret‘ has no attribute ‘StrBool‘”错误的解决办法,第1张

最近在研究pytest,进行接口测试的时候写下如下代码:

import requests

class TestRequest:

    # get请求,获取统一的鉴权码token接口
    def test_get_token(self):
        url = "https://api.weixin.qq.com/cgi-bin/token"
        data = {
            "grant_type": "client_credential",
            "appid": "wx74a8627810cfa308",
            "secret": "e40a02f9d79a8097df497e6aaf93ab80"
        }
        res = requests.get(url=url, params=data)
        print(res.json())
        TestRequest.access_token = res.json()['access_token']
if __name__ == '__main__':
    TestRequest().test_get_token()

        但是运行时会报错(报错信息很长,只截取有用信息):

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pytest_python_requests.py", line 50, in 
    SimpleType = String | t.StrBool | t.Bool | t.Float | t.Int | t.Null
AttributeError: module 'trafaret' has no attribute 'StrBool'

进程已结束,退出代码1

空套件


 

        网上搜索“AttributeError: module 'trafaret' has no attribute 'StrBool'”没有结果,看来大家普遍没有遇到这个问题,但是点进pytest_python_requests.py文件一看,有错误信息的:

         看错误信息,是说 'trafaret'没有'StrBool'方法,但是截图上可以看到,有个t.StrBool方法,因此我考虑,如果删除这个是不是就可以了,然后就删掉这个方法,再次运行。


        结果就通过了!

 

        实际上删掉这个方法报错信息还在,鼠标放上去会提示信息:

        这里是否处理是不会影响程序运行的。


所以我也没管,毕竟:

        “当你发现bug但程序依然运行时,请不要尝试修复bug”

 

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/568796.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存