我安装了coverage.py来测量我的Django项目的代码覆盖率。 (如此处所述:https://docs.djangoproject.com/en/1.6/topics/testing/advanced/#integration-with-coverage-py)
但我目前在我的项目中没有测试用例。因此,当我进行报道时,它说:
coverage run --source='.' manage.py test myapp
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
它清楚地说它运行了0次测试,但是当我说
时coverage report -m
它给我一份代码覆盖率为91%的报告。它也只查看我的模型包。它不会查看作为我的应用程序一部分的其他软件包。
所以当我给出
coverage run --source='.' manage.py test myapp/mypackage
它再次报告仅针对模型包的报道。
如何衡量应用的所有软件包的代码覆盖率?请帮助。提前谢谢。
myproject/
├── myapp
│ ├── models
│ ├── services
│ ├── statis
│ ├── templates
│ ├── utils
│ └── views
└── myproject
报告:
Name Stmts Miss Cover Missing
------------------------------------------------------------
manage 11 2 82% 8-9
myapp/__init__ 0 0 100%
myapp/admin 1 1 0% 1
myapp/models/__init__ 3 0 100%
myapp/models/form/__init__ 10 0 100%
myapp/models/form/items 57 0 100%
myapp/models/form/profile 14 0 100%
myapp/models/form/sections 10 0 100%
myapp/models/user/__init__ 21 0 100%
myapp/models/user/items 67 0 100%
myapp/models/user/profile 13 1 92% 9
myapp/models/user/sections 60 0 100%
myapp/tests 1 0 100%
myapp/urls 7 7 0% 1-9
myproject/__init__ 0 0 100%
myproject/manage 11 11 0% 2-16
myproject/settings 33 0 100%
myproject/urls 4 4 0% 1-6
myproject/wsgi 4 4 0% 10-14
------------------------------------------------------------
TOTAL 327 30 91%
答案 0 :(得分:6)
当代码覆盖中缺少模块时,首先要检查是否有任何丢失的__init__.py
文件。