自动化工具 求教:pytest 安装后,查看 pytest --version 报错————AttributeError:模块 “集合” 没有属性 “映射”

Ccrush · 2022年02月24日 · 最后由 Ccrush 回复于 2022年02月25日 · 3739 次阅读

Microsoft Windows 版本 10.0.19042.1526 Microsoft Corporation。保留所有权利。

C:\Users\user>pip list
Package Version


amqp 5.0.9
Appium-Python-Client 2.1.2
async-generator 1.10
atomicwrites 1.4.0
attrs 21.4.0
billiard 3.6.4.0
celery 5.2.3
certifi 2021.10.8
cffi 1.15.0
charset-normalizer 2.0.10
click 8.0.4
click-didyoumean 0.3.0
click-plugins 1.1.1
click-repl 0.2.0
colorama 0.4.4
cryptography 36.0.1
ddt 1.4.4
distlib 0.3.4
enum34 1.1.10
filelock 3.5.0
h11 0.13.0
idna 3.3
iniconfig 1.1.1
kombu 5.2.3
loguru 0.6.0
lxml 4.7.1
namedlist 1.8
outcome 1.1.0
packaging 21.3
pip 22.0.3
pipenv 2022.1.8
platformdirs 2.5.0
pluggy 1.0.0
prompt-toolkit 3.0.28
py 1.11.0
pycparser 2.21
pygame 2.1.2
pyOpenSSL 21.0.0
pyparsing 3.0.7
pytest 7.0.1
pytest-allure-adaptor 1.7.10
pytest-html 3.1.1
pytest-metadata 1.11.0
pytest-reportlog 0.1.2
pytz 2021.3
requests 2.27.1
selenium 4.1.0
setuptools 59.6.0
six 1.16.0
sniffio 1.2.0
sortedcontainers 2.4.0
toml 0.10.2
tomli 2.0.1
trio 0.19.0
trio-websocket 0.9.2
urllib3 1.26.8
vine 5.0.0
virtualenv 20.13.1
virtualenv-clone 0.5.7
wcwidth 0.2.5
win32-setctime 1.1.0
wsproto 1.0.0
C:\Users\user>pytest --version
Traceback (most recent call last):
File "C:\Python310\lib\runpy.py", line 196, in run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Python310\Scripts\pytest.exe__main
.py", line 7, in
File "C:\Python310\lib\site-packages_pytest\config__init
.py", line 188, in console_main
code = main()
File "C:\Python310\lib\site-packages_pytest\config__init
.py", line 146, in main
config = _prepareconfig(args, plugins)
File "C:\Python310\lib\site-packages_pytest\config__init
.py", line 325, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "C:\Python310\lib\site-packages\pluggy_hooks.py", line 265, in __call
_
return self.hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "C:\Python310\lib\site-packages\pluggy_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "C:\Python310\lib\site-packages\pluggy_callers.py", line 55, in _multicall
gen.send(outcome)
File "C:\Python310\lib\site-packages_pytest\helpconfig.py", line 102, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "C:\Python310\lib\site-packages\pluggy_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "C:\Python310\lib\site-packages\pluggy_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "C:\Python310\lib\site-packages_pytest\config__init
.py", line 1013, in pytest_cmdline_parse
self.parse(args)
File "C:\Python310\lib\site-packages_pytest\config__init
.py", line 1301, in parse
self._preparse(args, addopts=addopts)
File "C:\Python310\lib\site-packages_pytest\config__init
.py", line 1184, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "C:\Python310\lib\site-packages\pluggy_manager.py", line 287, in load_setuptools_entrypoints
plugin = ep.load()
File "C:\Python310\lib\importlib\metadata__init
.py", line 162, in load
module = import_module(match.group('module'))
File "C:\Python310\lib\importlib__init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 992, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "C:\Python310\lib\site-packages_pytest\assertion\rewrite.py", line 171, in exec_module
exec(co, module.
dict)
File "C:\Python310\lib\site-packages\allure__init
.py", line 1, in
from allure.pytest_plugin import MASTER_HELPER
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "C:\Python310\lib\site-packages_pytest\assertion\rewrite.py", line 171, in exec_module
exec(co, module.
dict)
File "C:\Python310\lib\site-packages\allure\pytest_plugin.py", line 9, in
from allure.common import AllureImpl, StepContext
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "C:\Python310\lib\site-packages_pytest\assertion\rewrite.py", line 171, in exec_module
exec(co, module.
dict)
File "C:\Python310\lib\site-packages\allure\common.py", line 19, in
from allure.structure import Attach, TestStep, TestCase, TestSuite, Failure, Environment, EnvParameter
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "C:\Python310\lib\site-packages_pytest\assertion\rewrite.py", line 171, in exec_module
exec(co, module.
dict_)
File "C:\Python310\lib\site-packages\allure\structure.py", line 14, in
class Attach(xmlfied('attachment',
File "C:\Python310\lib\site-packages\allure\rules.py", line 116, in xmlfied
class MyImpl(namedlist('XMLFied', [(item[0], None) for item in items])):
File "C:\Python310\lib\site-packages\namedlist.py", line 398, in namedlist
fields, defaults = _fields_and_defaults(typename, field_names, default, rename)
File "C:\Python310\lib\site-packages\namedlist.py", line 252, in _fields_and_defaults
if isinstance(field_names, _collections.Mapping):
AttributeError: module 'collections' has no attribute 'Mapping'
C:\Users\user>

最佳回复

查了下 3.10.0 release note ,里面移除了一个本身就即将废弃的 collections 的 Mapping 属性值。

相关 issue :https://bugs.python.org/issue39674

这个要 pytest 官方适配才能彻底解决,建议你先换个稍微不那么新的 python 版本吧,比如 3.8 之类的。

共收到 4 条回复 时间 点赞

查了下 3.10.0 release note ,里面移除了一个本身就即将废弃的 collections 的 Mapping 属性值。

相关 issue :https://bugs.python.org/issue39674

这个要 pytest 官方适配才能彻底解决,建议你先换个稍微不那么新的 python 版本吧,比如 3.8 之类的。

python3.10 不兼容 pytest 安装 python3.9🐶

感谢回答,确实是因为 Python3.10 和 pytest 兼容问题,在执行 pytest 用例时还会报测试框架意外退出的错误。更换低版本 python 后问题得到解决

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册