feat: Add test coverage reporting. Closes #701#712
feat: Add test coverage reporting. Closes #701#712mlodic merged 9 commits intointelowlproject:developfrom
Conversation
- Add .coveragerc configuration file - Define source paths (greedybear/) - Exclude migrations, tests, and generated files - Configure report formatting (show_missing, precision) - Set output formats for HTML and XML reports - Update CI workflow to generate coverage artifacts - Generate XML coverage report for download - Upload coverage reports as GitHub Actions artifacts - Add coverage summary to job summary for quick visibility - Set 30-day retention for coverage artifacts - Update .gitignore to exclude coverage artifacts - htmlcov/, .coverage, coverage.xml, etc. This implements Phase 1 (Local Coverage Setup) and Phase 2 (CI Integration) as discussed in issue intelowlproject#701. Coverage is already enabled in the CI workflow and will now generate detailed reports. Local usage: coverage run --source=greedybear manage.py test tests coverage report # Terminal output coverage html # Browser-viewable report in htmlcov/ Related: intelowlproject#701
Implementation Complete! 🎉I've implemented Phase 1 (Local Coverage Setup) and Phase 2 (CI Integration) as discussed in #701. How to UseLocal Development (Docker): # Coverage is automatically installed when you start containers
docker compose up -d
# Run tests with coverage
docker compose exec uwsgi python3 -m coverage run --source=greedybear manage.py test tests
# View coverage report in terminal
docker compose exec uwsgi python3 -m coverage report -m
# Generate HTML report (browser-viewable)
docker compose exec uwsgi python3 -m coverage html
# Then open htmlcov/index.html in your browser
# Generate XML report
docker compose exec uwsgi python3 -m coverage xmlNon-Docker Environments: pip install -r requirements/test.txt
coverage run --source=greedybear manage.py test tests
coverage report -mCI (Automatic):
|
Would be soon updating the docs repo once this is merged. |
There was a problem hiding this comment.
Pull request overview
This PR implements comprehensive test coverage reporting for GreedyBear, enabling developers to track code coverage both locally and in CI environments. The changes establish a foundation for monitoring test quality and identifying untested code paths.
Changes:
- Added
.coveragercconfiguration file with coverage settings for source tracking, exclusions, and report formatting - Enhanced CI workflow to generate coverage XML reports and upload them as artifacts with 30-day retention
- Auto-installed coverage package in local Docker development environment via modified entrypoint
- Created
requirements/test.txtfor non-Docker environments
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.coveragerc |
Configures coverage.py with source paths, omissions, report formatting, and exclusion patterns |
.github/workflows/_python.yml |
Adds coverage XML generation and artifact upload steps to CI pipeline |
docker/local.override.yml |
Modifies uwsgi service entrypoint to install coverage package before starting |
requirements/test.txt |
Defines test dependencies for non-Docker installations |
.gitignore |
Excludes coverage artifacts from version control |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add coverage auto-installation to local.override.yml - Coverage is now automatically installed when running docker compose - Developers no longer need to manually 'pip install coverage' - Add requirements/test.txt for non-Docker environments - Provides easy installation: pip install -r requirements/test.txt - Documents test dependencies This implements Option 4 as approved by @mlodic. Related: intelowlproject#701
docker/local.override.yml
Outdated
| - DJANGO_TEST_SERVER=True | ||
| - DJANGO_WATCHMAN_TIMEOUT=20 | ||
| entrypoint: > | ||
| sh -c "pip install --no-cache-dir coverage>=7.6.10 && |
There was a problem hiding this comment.
the problem about this is that we are not able to track updates of coverage package via dependabot. This is necessary from a maintainer point of view
There was a problem hiding this comment.
Thanks for the feedback! You're absolutely right - we need coverage tracked by Dependabot.
The Problem
Currently, coverage is installed at runtime via local.override.yml, which means:
- Dependabot can't track it
- Version updates won't be automated
Proposed Solutions
I can implement either of these approaches:
Option A: Add to requirements/project-requirements.txt
+ # Test coverage
+ coverage>=7.3.2- Dependabot tracks it automatically
- Simplest implementation
- Coverage available everywhere (production, dev, CI)
- Minimal overhead (~240KB)
- Adds test dependency to production image
Option B: Create requirements/dev-requirements.txt
# Development requirements
coverage>=7.3.2
Then update Dockerfile to conditionally install dev requirements:
ARG INSTALL_DEV=false
RUN if [ "$INSTALL_DEV" = "true" ]; then \
pip install -r requirements/dev-requirements.txt; \
fi- Dependabot tracks it automatically
- Clean separation (dev vs production)
- Production image stays lean
- More complex implementation
- Requires Dockerfile changes
requirements/test.txt
Outdated
| # Test requirements | ||
| # Automatically installed in local Docker setup via local.override.yml | ||
| # For manual installation: pip install -r requirements/test.txt | ||
| coverage>=7.6.10 |
There was a problem hiding this comment.
also this must be tracked here https://github.com/intelowlproject/GreedyBear/blob/main/.github/dependabot.yml
There was a problem hiding this comment.
Looking at .github/dependabot.yml (lines 4-9):
- package-ecosystem: "pip"
directory: "/requirements"So requirements/test.txt should be tracked automatically by the existing Dependabot config.
However, I see your concern: the current implementation installs coverage at runtime via local.override.yml:
entrypoint: >
sh -c "pip install --no-cache-dir coverage>=7.3.2 &&
exec /opt/deploy/greedybear/docker/entrypoint_uwsgi.sh"| @@ -0,0 +1,33 @@ | |||
| [run] | |||
There was a problem hiding this comment.
are you sure that this file is actually taken into account in the github action?
There was a problem hiding this comment.
Yes! The .coveragerc file is used by the GitHub Actions workflow.
Evidence
In .github/workflows/_python.yml:
Line 85-89 - Config path parameter:
coverage_config_path:
description: Path to the coverage.py config file
type: string
required: false
default: .coveragercLine 513 - Coverage command uses the config:
CMD="coverage run --rcfile=${{ inputs.coverage_config_path }}"Since pull_request_automation.yml doesn't override coverage_config_path, it uses the default value .coveragerc.
How it works
- PR triggers
pull_request_automation.yml - Calls
_python.ymlwithuse_coverage: true _python.ymluses defaultcoverage_config_path: .coveragerc- Tests run with:
coverage run --rcfile=.coveragerc manage.py test tests - Coverage respects our config (excludes migrations, tests, etc.)
4ef3a30 to
c0a406c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7989aaf to
c7fc345
Compare
- Fixed if __name__ == __main__ pattern
- Changed from dots (.__main__.:) to proper quotes ("__main__":)
- Copilot suggestion applied
Co-authored-by: GitHub Copilot
c7fc345 to
f69ea92
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Removed .coverage file from artifact upload - Prevents overwrites between different Python versions in matrix - XML report is sufficient for coverage analysis - Binary .coverage files are version-specific Co-authored-by: GitHub Copilot
|
Hi @mlodic The ProblemCurrently, coverage is installed at runtime via
Proposed SolutionsI can implement either of these approaches: Option A: Add to + # Test coverage
+ coverage>=7.3.2
Option B: Create Then update Dockerfile to conditionally install dev requirements: ARG INSTALL_DEV=false
RUN if [ "$INSTALL_DEV" = "true" ]; then \
pip install -r requirements/dev-requirements.txt; \
fi
|
|
Fine with the second option from my perspective |
Implements Option B as approved by @mlodic: - Create requirements/dev-requirements.txt with coverage>=7.3.2 - Add INSTALL_DEV build argument to Dockerfile - Update local.override.yml to use INSTALL_DEV=true - Remove requirements/test.txt (replaced by dev-requirements.txt) Benefits: - Dependabot tracks dev dependencies automatically - Clean separation between dev and production - Production image stays lean (no coverage) - Dev dependencies installed at build time, not runtime Usage: docker compose up --build # Local dev (includes coverage) docker build . # Production (no dev deps) Related: intelowlproject#701
c20b6ad to
9fb32f9
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Artifact name 'coverage-report-3.13' becomes 'coverage-report-3-13' - Prevents GitHub Actions naming conflicts with periods Co-authored-by: GitHub Copilot
|
Hi @mlodic the implementation is complete now. Re: Is
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @mlodic @regulartim can you run the CI / backend-tests, I just wanted to see whether the test coverage is working or not? |
|
the CI requires that at least a random change is pushed in the branch. You can just add a random log.debug() anywhere in the python code and that would do the trick. Then we can delete it before mergin the PR |
|
@mlodic I beleive CI Test was successful
NoteThe last commit added a temporary debug log to trigger CI. Once you confirm everything looks good, I'll push a revert commit to remove it before merging. |
This reverts commit a7aa941.
|
it works, you can see the results here: https://github.com/intelowlproject/GreedyBear/actions/runs/21190092088 |
|
Thanks @mlodic for testing |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
good job, thanks! |
Documentation QuestionHi @mlodic @regulartim, Since test coverage is primarily a maintainer concern (contributors may not need to know about it), should I still add it to the contributor's section docs repo? Or is this feature internal-only and doesn't require public documentation? Let me know. Thanks! |
|
To me it is not strictly necessary, thanks for asking |

Description
This PR implements comprehensive test coverage reporting for GreedyBear, enabling developers to track code coverage both locally and in CI.
Summary of changes:
.coveragercconfiguration file to define coverage settingsrequirements/test.txtfor non-Docker environments.gitignoreto exclude coverage artifactsRelated issues
Closes #701
Type of change
Checklist
developRuff) gave 0 errors