3

I have my Django project hooked up with Travis-CI and Coveralls.

The issue I'm facing is that when my data is posted to Coveralls from Travis, Coveralls seems to be taking into account all of the Django Framework and site-packages files in addition to my own app files:

enter image description here

The only coverage data I really care about is my app files - is there any way to only show coverage for stuff that I have written? Something like this:

enter image description here

My command on Travis seems like it only runs my own app tests, which seems like correct behavior. Here is my .travis.yml file:

language: python
python:
  - "3.4"
# command to install dependencies
install:
  - pip install -r requirements.txt --use-mirrors
  - pip install coveralls coverage
# command to run tests
script:
  - coverage run manage.py test
# addons
addons:
  postgresql: "9.4"
after_success:
  coveralls

Here is an example of one of the paths to a file that I don't want to be included in coveralls: /home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/utils/lru_cache.py

It seems like it has something to do with Travis' virtualenv...

4

1 回答 1

4

根据文档_coverage

运行代码时,该coverage run命令默认测量所有代码,除非它是 Python 标准库的一部分。

Django 不在标准库中,因此您需要指定应该排除它,或者只包含您自己的代码。在您的script中,您可以设置source(s) 的覆盖范围。例如,使用标准myapp

script:
  - coverage run --source=myapp manage.py test myapp
               # ^ set one or more comma-separated sources to cover

根据关于集成的 Django 文档,coverage您还可以使用它--source='.'来覆盖项目根目录中的所有文件。

于 2015-07-20T20:04:16.343 回答