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

最近在研究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 <module>
    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”

 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值