.coveragerc unable to locate files I want omitted

走远了吗. 提交于 2020-04-11 12:25:28

问题


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%

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.

Simplified project structure:

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

This is my 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

This is my .coveragerc:

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

This is my 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?


回答1:


Change .coveragerc to:

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


来源:https://stackoverflow.com/questions/54536483/coveragerc-unable-to-locate-files-i-want-omitted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!