Home > Enterprise >  Getting error: coverage.exceptions.ConfigError: File pattern can't include '**/**' wh
Getting error: coverage.exceptions.ConfigError: File pattern can't include '**/**' wh

Time:12-23

I am trying to generate code coverage for a python project. I am running the command:

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

This command should help me generate an html based coverage report, but I am getting the error:

  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 '**/**'

This is my coveragerc file:

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

I am unable to figure out the reason of the failure. We have been using this coveragerc for a while now and everything used to work fine. Please help.

CodePudding user response:

This is for the last release on December 18. Changed file pattern matching.

File path patterns are used for include and omit, and for combining path remapping. They follow common shell syntax:

* 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.

I think the configuration you are looking for is the following:

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