我正在运行pytest-cov
和pytest-django
使用tox
. 我有一个非常简单的tox.ini
文件,文件有限omit
。问题是当我运行pytest
using时tox -e unit
,我得到一个有限的覆盖率报告:
---------- coverage: platform darwin, python 3.7.4-final-0 -----------
Name Stmts Miss Cover Missing
----------------------------------------------------------------------------
components/__init__.py 0 0 100%
components/client/__init__.py 0 0 100%
components/client/admin.py 27 0 100%
components/client/factories.py 57 0 100%
components/client/models.py 62 0 100%
components/controller/__init__.py 0 0 100%
components/controller/admin.py 62 6 90% 96-97, 109-110, 122-123
components/controller/management/__init__.py 0 0 100%
components/controller/models.py 107 6 94% 19, 31, 54, 92, 105, 132
components/personal/__init__.py 0 0 100%
components/personal/admin.py 24 0 100%
components/personal/factories.py 39 0 100%
components/personal/models.py 81 16 80% 23, 36, 49, 62, 72, 75-76, 92-104
server/__init__.py 3 0 100%
server/celery.py 10 1 90% 30
server/config/__init__.py 1 0 100%
server/settings.py 52 0 100%
server/test.py 56 33 41% 16-19, 43, 48-49, 63-88, 94-105, 112-115
----------------------------------------------------------------------------
TOTAL 589 62 89%
我所有的 Django 应用程序components
都有许多文件应该包含在报告中,包括apps
、serializers
、signals
、urls
和views
(标准 Django 结构)。有人知道我缺少什么吗?我在 , , 和 的各种文档中所读到的tox.ini
内容似乎与我在 、 、 和 的各种文档中所读到的完全一致pytest
,pytest-django
但 pytest-cov
我coverage
一定遗漏了一些重要的东西!
tox.ini
[tox]
; The only reason we'd want to `sdist` is if we distributed this as a Python package in PyPI, so let's skip it:
skipsdist = True
envlist =
{py37}-django{2}
lint
skip_missing_interpreters = true
[testenv]
whitelist_externals = *
passenv = *
deps = -rrequirements-test.txt
commands = {[testenv:unit]commands}
[testenv:unit]
deps = {[testenv]deps}
commands = pytest {posargs:--cov=project-name}
[pytest]
DJANGO_SETTINGS_MODULE = server.settings
python_files = tests.py test_*.py *_tests.py
addopts =
-v -s
--color=yes
--cov
--cov-append
--cov-report=term-missing
--cov-config=tox.ini
[coverage:report]
show_missing = True
omit =
*/usr/*
*/.tox/*py
*/.virtualenvs/*
*/migrations/*
*/tests/*
[report]
omit =
*/usr/*
*/.tox/*
*/migrations/*
*/tests/*