Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda