Coverage - PermissionError: [Errno 1] Operation not permitted

Coverage - PermissionError: [Errno 1] Operation not permitted

我使用 pytestcoverage 模块来测试用例和代码覆盖率。

从项目根目录,我可以执行 pytest -v 但不能执行 pytest -v --cov=./ (下面的堆栈跟踪)

我设置PYTHONPATH为项目根目录

目录权限和所有权为 drwxr-xr-xsaurabh staff。终端应用程序具有完整的磁盘访问权限。

我的 .coveragerc(位于项目根目录)看起来像:

[run]
data_file = tests/coverage/
omit = data-structures/*

[html]
directory = tests/coverage/html_report/

[xml]
output = tests/coverage/coverage.xml

堆栈跟踪

Traceback (most recent call last):
  File "/Users/saurabh/Desktop/Data Structures/data-structures/bin/pytest", line 10, in <module>
    sys.exit(console_main())
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/_pytest/config/__init__.py", line 187, in console_main
    code = main()
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
    config = outcome.get_result()  # type: Config
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1280, in parse
    self._preparse(args, addopts=addopts)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1186, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pytest_cov/plugin.py", line 126, in pytest_load_initial_conftests
    plugin = CovPlugin(options, early_config.pluginmanager)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pytest_cov/plugin.py", line 177, in __init__
    self.start(engine.Central)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pytest_cov/plugin.py", line 199, in start
    self.cov_controller.start()
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pytest_cov/engine.py", line 44, in ensure_topdir_wrapper
    return meth(self, *args, **kwargs)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/pytest_cov/engine.py", line 220, in start
    self.cov.erase()
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/coverage/control.py", line 582, in erase
    self._data.erase(parallel=self.config.parallel)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/coverage/sqldata.py", line 730, in erase
    file_be_gone(self._filename)
  File "/Users/saurabh/Desktop/Data Structures/data-structures/lib/python3.8/site-packages/coverage/misc.py", line 148, in file_be_gone
    os.remove(path)
PermissionError: [Errno 1] Operation not permitted: '/Users/saurabh/Desktop/Data Structures/tests/coverage'

我是不是做错了,或者有什么解决方法的建议吗?


更新:

当我删除 data_file = tests/coverage/ 时,覆盖命令工作正常。但这应该发生吗,因为有一个选项可以更改 data_file here ?

我可以通过将 .coveragerc 更改为:

来使其正常工作
[run]
omit = data-structures/*
data_file = tests/coverage/.coverage

[html]
directory = tests/coverage/html_report/

[xml]
output = tests/coverage/coverage.xml