pytest (Hint: make sure your test modules/packages have valid Python names.)_make sure your test mod

书写apiTest demo时,运行pytest框架,遇到make sure your test modules/packages have valid Python names.错误,排查过程如下:

关键语句:

ImportError while importing test module 'F:\project\pytestStudy\ApiTest\testcases\test_api.py'.
Hint: make sure your test modules/packages have valid Python names.
E   ImportError: cannot import name 'Mapping' from 'collections' (E:\python\lib\collections\__init__.py)

1.直接搜索make sure your test modules/packages have valid Python names.错误

经过多轮寻找,终于找到以下文章:pytest (Hint: make sure your test modules/packages have valid Python names.)_make sure your test modules have valid python name-CSDN博客

尝试文中的几种方案,发现都与我的情况不符。

2. 因此转而搜索ImportError: cannot import name 'Mapping' from 'collections'

一下就找到问题所在,原来是:无法从“集合”导入名称“映射”,因为Python3.10版本以后对requests 库进行调整,collections中不能直接调用方法Mapping,MutableMapping

  办法就是:找到引用collections模块的__init__.py文件,调整从abc导入

参考文章:

Python错误:ImportError: cannot import name ‘Mapping‘ from ‘collections‘ – HandsomeFa – 博客园 (cnblogs.com)

应当首先从error提示查找。

作者:qq_42898282

物联沃分享整理
物联沃-IOTWORD物联网 » pytest (Hint: make sure your test modules/packages have valid Python names.)_make sure your test mod

发表回复