运行py.test时的.coveragerc文件位置

Chr*_*olz 7 python unit-testing code-coverage pytest

我试图让pytest运行与coveragerc文件一起工作.我的.coveragerc文件中没有使用设置,所以我猜这个文件根本就没用过.

看下面我的项目结构和pytest调用!我究竟做错了什么?

项目:

basepath/lib/
basepath/.coveragerc
basepath/test/test_lib
basepath/test/run.py
Run Code Online (Sandbox Code Playgroud)

我从virtualenv调用test/run.py.

basepath$ python test/run.py
Run Code Online (Sandbox Code Playgroud)

run.py

import pytest
pytest.main('test/test_lib -v --cov-report xml --cov lib --cov-config .coveragerc')
Run Code Online (Sandbox Code Playgroud)

我试图在不同的目录中移动.coveragerc,即lib /,test /,test/test_lib /但是没有一个工作.

我希望在.coveragerc中设置一个名为"xxxcoverage"的覆盖文件,但我总是得到默认的.coverage

.coveragerc

[run]
data_file = xxxcoverage
Run Code Online (Sandbox Code Playgroud)

Chr*_*olz 5

一遍又一遍地阅读pytest文档...我发现了我的“错误”:
在这里它说:

请注意,此插件可控制某些选项,并且在配置文件中设置该选项将无效。这些包括指定要测量的源(源选项)和所有数据文件处理(data_file和并行选项)。

因此我的测试没有用,因为.coveragerc中的data_file选项无效。

我测试了忽略选项,它起作用了!

.coveragerc 必须将其放置在如上所述的基本路径中(并预期)