获取错误:coverage.exceptions.ConfigError:在为 python 项目生成覆盖率时,文件模式不能包含"**/**"



我正在尝试为python项目生成代码覆盖率。我正在运行命令:

pytest --cov-config=./coveragerc --cov-report html:target/coverage --cov=./

这个命令应该帮助我生成一个基于html的覆盖率报告,但是我得到了错误:

+ pytest --cov-config=./coveragerc --cov-report html:target/coverage --cov=./
Traceback (most recent call last):
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/bin/pytest", line 8, in <module>
sys.exit(console_main())
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/_pytest/config/__init__.py", line 190, in console_main
code = main()
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/_pytest/config/__init__.py", line 148, in main
config = _prepareconfig(args, plugins)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/_pytest/config/__init__.py", line 329, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_callers.py", line 55, in _multicall
gen.send(outcome)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
config: Config = outcome.get_result()
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1058, in pytest_cmdline_parse
self.parse(args)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1346, in parse
self._preparse(args, addopts=addopts)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1248, in _preparse
self.hook.pytest_load_initial_conftests(
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_hooks.py", line 265, in __call__
return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_manager.py", line 80, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_callers.py", line 60, in _multicall
return outcome.get_result()
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_result.py", line 60, in get_result
raise ex[1].with_traceback(ex[2])
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pluggy/_callers.py", line 39, in _multicall
res = hook_impl.function(*args)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pytest_cov/plugin.py", line 152, in pytest_load_initial_conftests
plugin = CovPlugin(options, early_config.pluginmanager)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pytest_cov/plugin.py", line 203, in __init__
self.start(engine.Central)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pytest_cov/plugin.py", line 225, in start
self.cov_controller.start()
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pytest_cov/engine.py", line 44, in ensure_topdir_wrapper
return meth(self, *args, **kwargs)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/pytest_cov/engine.py", line 234, in start
self.cov.start()
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/coverage/control.py", line 603, in start
self._init_for_start()
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/coverage/control.py", line 557, in _init_for_start
self._inorout.configure(self.config)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/coverage/inorout.py", line 267, in configure
self.omit_match = GlobMatcher(self.omit, "omit")
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/coverage/files.py", line 288, in __init__
self.re = globs_to_regex(self.pats, case_insensitive=env.WINDOWS)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/coverage/files.py", line 372, in globs_to_regex
rx = join_regex(map(_glob_to_regex, patterns))
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/coverage/misc.py", line 185, in join_regex
regexes = list(regexes)
File "/home/jenkins/agent/workspace/change_dx-airflow_cd-flow_PR-106/.pyenv-home-jenkins-.pyenv-shims-python/lib/python3.8/site-packages/coverage/files.py", line 345, in _glob_to_regex
raise ConfigError(f"File pattern can't include {m[0]!r}")
coverage.exceptions.ConfigError: File pattern can't include '**/**'

这是我的coveragerc文件:

[run]
omit =
test/*
**/**site-packages**/**
**__init__.py

我无法找出失败的原因。我们使用这种覆盖已经有一段时间了,一切都很好。请帮助。

这是12月18日的最后一个版本。更改了文件模式匹配。

文件路径模式用于include和省略,以及组合路径重新映射。它们遵循常见的shell语法:

* matches any number of file name characters, not including the directory separator.

? matches a single file name character.

** matches any number of nested directory names, including none.

Both / and will match either a slash or a backslash, to make cross-platform matching easier.

我认为你正在寻找的配置如下:

[run]
omit =
test/**
*/*site-packages*/**
*__init__.py

最新更新