Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
Why coverage doesn't report anything on Djangos views.py?

I have a class based view in a Django app that looks something like this :

class CBView(View):

    def get(self, request, client, *args, **kwargs):
        output1 = self.method1(argument1)
        output2 = self.method2(argument2)
        # Rest of the method implementation
        ...

        return response

    def method1(self, argument1):
        # Implementation
        ... 

        return output1

    def method2(self, argument2):
        # Implementation
        ...

        return output2 

And I'm trying to write unit tests for the 'easy' class methods, namely method1 and method2. The tests looks like this :

class TestCBView(TestCase):

    def setUp(self):
        self.view = CBView()

    def test_method1(self):
        # Testing that output1 is as expected
        ...
        output1 = self.view.method1(argument1)
        ...
        self.assertEquals(output1, expected_output1)

    def test_method2(self):
        # Testing that output2 is as expected
        ...
        output2 = self.view.method2(argument2)
        ...
        self.assertEquals(output2, expected_output2)

After that, I run:

coverage run ./manage.py test django_app.tests.test_cbview

Which runs all the tests successfully, then I try to run:

coverage report -m django_app/views.py

And I get :

Name    Stmts   Miss  Cover   Missing
-------------------------------------
No data to report.

Am I doing something wrong ?

I'm using Coverage.py, version 4.0.3., Django 1.8.15 and Python 2.7.13.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I just had the same problem. It appeared I had some not migrated data, so after I ran in the terminal

python manage.py makemigrations
python manage.py migrate

and I tried again with

coverage html --include=django_app/views.py
coverage run manage.py test django_app.tests

everything was already fine.

about 4 years ago · Santiago Trujillo Report

0

When running tests with coverage it generates the .coverage file which is in a private format and not intended to be read directly. This file contains the raw reports which will be used to show the report for you, either on console or in html format with coverage html. So normally if the tests were ran, the .coverage file must be there in the directory from which you launched the command coverage run ./manage.py test django_app.tests.test_cbview and then being under that directory, you can hit coverage report ... and should work.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!