.coveragerc 无法找到我想省略的文件 [英] .coveragerc unable to locate files I want omitted

查看:55
本文介绍了.coveragerc 无法找到我想省略的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tox 使用 pytestpytest-cov 插件自动运行我的测试.但是,我收到了我在 .coveragerc 中省略的文件的覆盖率报告:

I am using tox to automatically run my tests using pytest and pytest-cov plugin. However, I'm getting coverage reports for the files I omitted in .coveragerc:

(env) alex@smartalex-pc:~/.repos/codelib/github/project$ tox

[...]

../../../tests/test_module1.py::test_func PASSED  [  3%]

[...]

../../../tests/test_module2.py::test_func PASSED  [100%]

----------- coverage: platform linux, python 3.6.7-final-0 -----------
Name                                                                                                   Stmts   Miss  Cover
--------------------------------------------------------------------------------------------------------------------------
/home/alex/.repos/codelib/github/project/.tox/py36/lib/python3.6/site-packages/package/__init__.py             0      0   100%
/home/alex/.repos/codelib/github/project/.tox/py36/lib/python3.6/site-packages/package/__main__.py             2      2     0%
/home/alex/.repos/codelib/github/project/.tox/py36/lib/python3.6/site-packages/package/application.py         40      0   100%
/home/alex/.repos/codelib/github/project/.tox/py36/lib/python3.6/site-packages/package/core.py                73      0   100%
/home/alex/.repos/codelib/github/project/.tox/py36/lib/python3.6/site-packages/package/user_interface.py      45      0   100%
--------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                                                        160      2    99%

似乎tox 没有使用我的.coveragerc.我尝试使用 --cov-config={toxinidir}/.coveragerc 明确指定配置文件,但我再次得到相同的结果.

It seems that tox does not use my .coveragerc. I tried to explicitly specify the config file with --cov-config={toxinidir}/.coveragerc, but I get the same result again.

简化的项目结构:

package/
    __init__.py
    __main__.py
    application.py
    core.py
    user_interface.py
tests/
    test_module1.py
    test_module2.py
.coveragerc
pytest.ini
setup.py
tox.ini

这是我的tox.ini:

[tox]
envlist = py36

[testenv]
changedir = {envtmpdir}
deps = 
    trio
    -r dev-requirements.txt
commands =
    pytest -v {toxinidir}/tests --cov=package --cov-config={toxinidir}/.coveragerc

这是我的.coveragerc:

[run]
omit =
    package/__main__.py
    package/__init__.py

这是我的pytest.ini:

[pytest]
trio_mode = true

我认为这已经足够了,但如果您需要更多输出/信息,请告诉我.

I think this is enough but let me know if you need more output/information.

我该如何解决这个问题?

How can I overcome the issue?

推荐答案

将 .coveragerc 更改为:

Change .coveragerc to:

[run]
omit =
    */package/__main__.py
    */package/__init__.py

这篇关于.coveragerc 无法找到我想省略的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆