Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude South migrations from coverage reports using coverage.py

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?

like image 470
Jonas Obrist Avatar asked Dec 21 '10 15:12

Jonas Obrist


People also ask

What is Pragma no cover?

That exact # pragma: no cover is the hint that the part of code should be ignored by the tool -- see Excluding code from coverage .

How do I use Django coverage?

With Django's Test Runner. If you're using manage.py test , you need to change the way you run it. You need to wrap it with three coverage commands like so: $ coverage erase # Remove any coverage data from previous runs $ coverage run manage.py test # Run the full test suite Creating test database for alias 'default'.. ...

How does Django keep track of migrations?

Django keeps track of applied migrations in the Django migrations table. Django migrations consist of plain Python files containing a Migration class. Django knows which changes to perform from the operations list in the Migration classes. Django compares your models to a project state it builds from the migrations.


2 Answers

The solution was:

[run] omit = ../*migrations* 
like image 150
Jonas Obrist Avatar answered Sep 27 '22 03:09

Jonas Obrist


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* 
like image 34
Ned Batchelder Avatar answered Sep 27 '22 03:09

Ned Batchelder