gpt4 book ai didi

python - 无法再运行 pytest,因为 importlib-metadata entry_points() 因 configparser.DuplicateOptionError 失败

转载 作者:行者123 更新时间:2023-12-01 07:45:21 27 4
gpt4 key购买 nike

pluggypytest 使用。最近,pluggy 更改为使用 importlib-metadata 而不是 pkg-resources。从那时起我就不能再运行测试了。我直接从我的库 (bliss) 源目录启动 pytest就像我一直做的那样,但现在一开始就失败了:

Traceback (most recent call last):
File "/opt/conda/envs/testenv/bin/pytest", line 11, in <module>
sys.exit(main())
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 63, in main
config = _prepareconfig(args, plugins)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 207, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/pluggy/callers.py", line 203, in _multicall
gen.send(outcome)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/helpconfig.py", line 94, in pytest_cmdline_parse
config = outcome.get_result()
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 687, in pytest_cmdline_parse
self.parse(args)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 895, in parse
self._preparse(args, addopts=addopts)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 836, in _preparse
self._consider_importhook(args)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 784, in _consider_importhook
self._mark_plugins_for_rewrite(hook)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 806, in _mark_plugins_for_rewrite
for name in _iter_rewritable_modules(package_files):
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 625, in _iter_rewritable_modules
for fn in package_files:
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/_pytest/config/__init__.py", line 802, in <genexpr>
if any(ep.group == "pytest11" for ep in dist.entry_points)
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 226, in entry_points
return EntryPoint._from_text(self.read_text('entry_points.txt'))
File "/opt/conda/envs/testenv/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 109, in _from_text
config.read_string(text)
File "/opt/conda/envs/testenv/lib/python3.7/configparser.py", line 722, in read_string
self.read_file(sfile, source)
File "/opt/conda/envs/testenv/lib/python3.7/configparser.py", line 717, in read_file
self._read(f, source)
File "/opt/conda/envs/testenv/lib/python3.7/configparser.py", line 1091, in _read
fpname, lineno)
configparser.DuplicateOptionError: While reading from '<string>' [line 16]: option 'bliss' in section 'console_scripts' already exists

我的setup.py看起来像这样:

def main():
...
setup(name=meta['name'],
...
entry_points={
"console_scripts": [
"bliss = bliss.shell.cli.main:main",
...
]
},
...
)

console_scripts 部分没有重复

我不知道为什么会收到此错误消息...

我将问题范围缩小到importlib-metadata,特别是它创建了一个 ConfigParser 对象来“解析”entry_points.txt 文件(它不存在 !我不知道它来自哪里!),如果我在构造函数它使我的测试再次运行。

最佳答案

通过更多信息,console_scripts 有两个条目,如下所示:

    entry_points={
"console_scripts": [
"bliss = bliss.shell.cli.main:main",
...
"Bliss = ...",
]

importlib-metadata 当前存在一个错误,它以不区分大小写的方式解析此文件

这里有一个补丁可以解决这个问题:https://gitlab.com/python-devs/importlib_metadata/merge_requests/76

关于python - 无法再运行 pytest,因为 importlib-metadata entry_points() 因 configparser.DuplicateOptionError 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56491266/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com