1

我正在使用和插件tox自动运行我的测试。但是,我正在获取我在以下文件中省略的文件的覆盖率报告:pytestpytest-cov.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,但我再次得到相同的结果。

简化的项目结构:

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

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

我该如何克服这个问题?

4

1 回答 1

1

将 .coveragerc 更改为:

[run]
omit =
    */package/__main__.py
    */package/__init__.py
于 2019-02-05T14:30:16.730 回答