Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nosetests and Coverage not excluding lines

Running into a small problem with some code coverage using nosetests and coverage with a Django web application. I have created a .coveragerc file to exclude a huge amount of code (things like class declarations) but I'm still getting some weird results.

Here is my .coveragerc file:

[run]
omit = ../*migrations*, ../*admin.py

[report]
show_missing = True
exclude_lines =
         pragma: no cover
         from
         = models\.

This is an example of one of the models.py files:

from django.db import models

class Query(models.Model):
    variable1 = models.CharField(max_length=100)
    variable2 = models.CharField(max_length=100)
    variable3 = models.CharField(max_length=100)
    variable4 = models.CharField(max_length=100)
    variable5 = models.CharField(max_length=100)
    id = models.AutoField(primary_key=True)

def some_function(self):
     self.variable1 = self.variable2 + self.variable3 + self.variable4 + self.variable 5
     return self.variable1

So when I run code coverage, the issue I run into is that despite me telling coverage to explicitly exclude anything with the string "= models.", it still says the lines are missing in the report given through the command line. This is making it very hard to determine which lines I'm actually failing to cover in my test cases. Can anyone offer some insight to this?

like image 792
Michael Platt Avatar asked Jul 29 '16 17:07

Michael Platt


People also ask

How do I know which nosetests coverage plugin is installed?

Depending on the version of coverage installed, the included plugin may override the nose builtin plugin, or be available under a different name. Check nosetests --help or nosetests --plugins to find out which coverage plugin is available on your system.

What is [nose_cover_Min_percentage]?

Minimum percentage of coverage for tests to pass [NOSE_COVER_MIN_PERCENTAGE] Include all python files under working directory in coverage report. Useful for discovering holes in test coverage if not all files are imported by the test suite. [NOSE_COVER_INCLUSIVE] class nose.plugins.cover. Coverage ¶

How to include tests from executable files in nose?

It is important to note that the default behavior of nose is to not include tests from files which are executable. To include tests from such files, remove their executable bit or use the –exe flag (see ‘Options’ section below). To specify which tests to run, pass test names on the command line:

How do I include tests in a nose test case?

TestCase subclasses may do the same or use the various TestCase methods available. It is important to note that the default behavior of nose is to not include tests from files which are executable. To include tests from such files, remove their executable bit or use the –exe flag (see ‘Options’ section below).


1 Answers

Your .coveragerc file should list things to exclude starting from the root of your directory.

For example:

proj
|-- app1
   |
   -- models.py
   -- migrations.py
|-- app2

Then your coverage.rc file should look like:

[run]
omit = app1/migrations.py, app1/admin.py

or

[run]
omit = proj/*/migrations.py, proj/*/admin.py
like image 157
Alex Avatar answered Oct 23 '22 11:10

Alex