31

I use coverage.py to check the test coverage of my django application. However since I use South for my database migrations, all those files show up with 0% and mess up the overall percentage.

I already tried using --omit=*migrations* in both run and report (and both) but that didn't work.

I tried versions 3.4 and latest revision from Bitbucket as of Dec 20th 2010 with the same result.

Any ideas how I can get coverage.py to actually ignore the migrations folders?

Jonas Obrist
  • 336
  • 3
  • 4

6 Answers6

29

The solution was:

[run]
omit = ../*migrations*
Jonas Obrist
  • 291
  • 2
  • 2
  • I'm using nose tests which don't let you pass in all of the arguments into coverage.py and this worked for me as well. – Evan R. Sep 11 '12 at 06:32
27

You should be able to match against the migrations directory to omit those files. Have you tried quoting the argument? Depending on your OS and shell, it may be expanding those asterisks prematurely. Try it like this:

--omit='*migrations*'

Alternately, you could put the switch into a .coveragerc file:

[run]
omit = *migrations*
Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
2

Latest version of django-jenkins has new option COVERAGE_WITH_MIGRATIONS that would exclude migrations. It's not in PyPI yet so you need to install it with pip/easy_install specyfing url git url as source.

DimmuR
  • 281
  • 2
  • 5
1

Have you tried django_coverage. I think it handles this kind of problem.

luc
  • 41,928
  • 25
  • 127
  • 172
0

This worked for me:

coverage run --source='.' --omit='*/migrations/*.py' manage.py test
Pang
  • 9,564
  • 146
  • 81
  • 122
Torsten Engelbrecht
  • 13,318
  • 4
  • 46
  • 48
-3

try:

coverage run --source=. manage.py test app_name

this ignores third party code and fixes your % problem

user1422535
  • 749
  • 1
  • 6
  • 11