Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

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.

over 4 years ago · Santiago Trujillo Denunciar

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.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda