Skip to content

Coverage data only changes for tests.py, not for application code when running Django app tests #1995

@leofernandesmo

Description

@leofernandesmo

Describe the bug
I'm experiencing an issue when trying to measure code coverage for my Django project using Coverage.py. When I run the tests for a specific app, the coverage report only changes for the tests.py file of that app. The coverage for the remaining application code remains unchanged. If I run the tests.py from another app in the same project, the coverage report is exactly the same, except for the coverage of the newly executed tests.py file.

It seems that the coverage data is being masked or affected by Django's internal task execution, and the actual application code is not being measured as expected.

To Reproduce
0. Run the command: coverage run --rcfile=".coveragerc" manage.py runserver

  1. Run tests for one Django app and generate a coverage report: Eg.: docker exec -ti <container_name> coverage run --source='.' manage.py test <app_name>.
  2. Generate the report and repeat the tst execution to another app.
  3. Observe that only the tests.py file for that app shows coverage changes.
  4. Run tests for another app in the same project.
  5. Notice that the coverage report only changes for the new tests.py file, with no changes in the rest of the application code.
  6. I expect the coverage report to reflect the code executed in the application modules, not just the tests.py files.

A clear and concise description of what you expected to happen.

Additional context
It appears that Coverage.py is not tracking the execution of the actual application code during Django test runs, possibly due to the way Django manages test execution or subprocesses. Any guidance or workaround would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions