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

2024-09-27 17:55:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让pytest运行来处理coveragerc文件。我的.coveragerc文件中的设置未使用,因此我猜该文件根本未使用。

请参阅下面的项目结构和pytest调用!我做错什么了?

项目:

basepath/lib/
basepath/.coveragerc
basepath/test/test_lib
basepath/test/run.py

我从virtualenv调用test/run.py

basepath$ python test/run.py

运行.py

import pytest
pytest.main('test/test_lib -v --cov-report xml --cov lib --cov-config .coveragerc')

我试图将.coveragerc移动到不同的目录中,即lib/、test/、test/test_lib/,但它们都不起作用。

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

.覆盖范围

[run]
data_file = xxxcoverage

Tags: 文件项目runpytestvirtualenvpytestlib
1条回答
网友
1楼 · 发布于 2024-09-27 17:55:45

一遍又一遍地阅读pytest文档……我发现了自己的“错误”:
Here上面写着:

Note that this plugin controls some options and setting the option in the config file will have no effect. These include specifying source to be measured (source option) and all data file handling (data_file and parallel options).

所以我的测试没用,因为.coveragerc中的data_file选项没有任何效果。

我用省略选项进行了测试,结果成功了!

.coveragerc必须按上述(和预期)放置在基径中

相关问题 更多 >

    热门问题