coveragepy / coveragepy/coveragepy

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

Open
#1,995 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
3.4k
Forks
525
Avg merge
18h 27m
Merged PRs (30d)
6

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported sequence with coverage run --rcfile=".coveragerc" manage.py runserver and the two manage.py test <app_name> commands in the issue. Compare the generated coverage reports for application modules and each app's tests.py; done means executed application code is reflected rather than only the test files.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, docker, python
Domain
backend, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.