[TIP] impossible coverage results - django, django-nose, nose-cov, coverage

Ned Batchelder ned at nedbatchelder.com
Mon Jan 18 18:32:51 PST 2016

On 1/18/16 2:28 PM, Chris Withers wrote:
> Hi Ned,
> After some changes to unwind some knotty import loops in a big Django 
> project, we're now seeing coverage report seemingly impossible 
> results: looking at one module, I see coverage has dropped from 80+% 
> to 27%, with the lines-no-longer-covered being those that would have 
> had to execute during import time.

A common problem with the django-nose-cov plugin ecosystem is that 
coverage doesn't start until after many modules are already imported.  I 
usually recommend that coverage run the test runner, instead of the 
other way around.  This ensures that coverage measures everything.

> Have you ever seen behaviour like this? If so, what should we look out 
> for?
> Sadly, the stack is not a simple one:
> Django's test runner with the latest version of the django-nose 
> plugin, version 1.6 of the nose-cov plugin, 1.15.0 of cov-core and 
> 4.0.3 of coverage itself.

If the coverage-runs-the-test-runner idea doesn't fix it, send me the 
details of how to run the stack.  Usually it isn't a problem to get 
everything going.

> Any help gratefully received!
> Chris

More information about the testing-in-python mailing list