Search code examples
djangounit-testingcode-coveragetravis-cicoveralls

Remove tests from coveralls.io?


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...


Solution

  • Per the coverage documentation:

    When running your code, the coverage run command will by default measure all code, unless it is part of the Python standard library.

    Django isn't in the standard library, so you will need to specify that it should be excluded, or that only your own code should be included. In your script you can set the source(s) for coverage. For example, with the standard myapp:

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

    Per the Django docs on coverage integration you can also use --source='.' to cover all files within the project root.