Codecov Integration Setup¶
AIMQ uses Codecov to track test coverage and display coverage reports on pull requests. This guide will help you set up Codecov for your AIMQ repository.
What is Codecov?¶
Codecov is a code coverage reporting tool that: - Visualizes test coverage in pull requests - Tracks coverage trends over time - Shows which lines are covered/uncovered by tests - Provides coverage badges for README.md - Free for open source projects
Prerequisites¶
- GitHub repository with AIMQ project
- Admin access to the repository
- Codecov account (free for public repositories)
Setup Steps¶
1. Sign Up for Codecov¶
- Visit https://codecov.io
- Click "Sign up with GitHub"
- Authorize Codecov to access your GitHub account
2. Add Your Repository¶
- In Codecov dashboard, click "Add new repository"
- Find
bldxio/aimqin the list - Click "Setup repo"
- Codecov will provide an upload token
3. Add Codecov Token to GitHub¶
- Go to your GitHub repository:
https://github.com/bldxio/aimq - Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Add the following secret:
- Name:
CODECOV_TOKEN - Value: The token from Codecov dashboard
- Click Add secret
4. Verify Integration¶
The CI workflow (.github/workflows/ci.yml) is already configured to upload coverage reports to Codecov. Once the token is added:
- Push a commit or create a PR
- Wait for CI to complete
- Check the Codecov dashboard for coverage report
- PR comments will show coverage changes
Understanding Coverage Reports¶
In Pull Requests¶
Codecov will comment on PRs with: - Coverage changes: How much coverage increased/decreased - File-level changes: Which files have coverage changes - Patch coverage: Coverage of lines changed in the PR
Example comment:
In Codecov Dashboard¶
The dashboard shows: - Overall coverage: Project-wide test coverage percentage - Coverage sunburst: Visual breakdown by file/directory - Coverage trend: Historical coverage over time - Uncovered lines: Specific lines that need tests
Adding Coverage Badge to README¶
After setup, add the Codecov badge to your README.md:
[](https://codecov.io/gh/bldxio/aimq)
Current Coverage Status¶
AIMQ currently has 89%+ test coverage. Our goal is to maintain coverage above 85%.
Coverage Configuration¶
Coverage is configured in pyproject.toml:
[tool.coverage.run]
branch = true
source = ["aimq"]
omit = ["src/aimq/commands/shared/templates/*"]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if self.debug:",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"pass",
"raise ImportError",
]
show_missing = true
skip_empty = true
CI Workflow Integration¶
The CI workflow uploads coverage only for Python 3.11 to avoid duplicate reports:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: matrix.python-version == '3.11'
with:
file: ./coverage.xml
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Running Coverage Locally¶
To generate coverage reports locally:
# Run tests with coverage
just test-cov
# Or manually:
uv run pytest --cov=src/aimq --cov-report=term-missing --cov-report=html
# Open HTML report in browser
open htmlcov/index.html
Coverage Guidelines¶
What to Test¶
- ✅ Core business logic (Worker, Queue, Job)
- ✅ Public APIs and functions
- ✅ Error handling paths
- ✅ Edge cases and boundary conditions
- ✅ Data transformations and validations
What Can Be Excluded¶
- ❌ Third-party library code
- ❌ Generated code (templates)
- ❌ Debug/development code
- ❌ Simple getters/setters
- ❌ Type stubs and protocols
Use # pragma: no cover to exclude specific lines:
Troubleshooting¶
Coverage Not Uploading¶
- Check CI logs for upload errors
- Verify
CODECOV_TOKENis set in GitHub secrets - Check Codecov status page: https://status.codecov.io
Coverage Decreased Unexpectedly¶
- Check Codecov PR comment for details
- Review which lines are uncovered
- Add tests for new code paths
- Check if tests are failing silently
Coverage Too Low¶
- Run
just test-covlocally to see missing coverage - Identify critical paths without tests
- Write tests for high-value code first
- Gradually increase coverage over time
Best Practices¶
- Write tests before merging - Ensure new code has adequate coverage
- Review coverage reports - Check Codecov comments on PRs
- Don't game the system - 100% coverage doesn't mean quality tests
- Focus on critical paths - Prioritize testing important functionality
- Keep coverage above 85% - Our project standard
Resources¶
- Codecov Documentation
- Understanding Coverage Reports
- Python Coverage.py Guide
- Testing Best Practices
Support¶
If you encounter issues with Codecov integration: 1. Check the Codecov Community Forum 2. Review CI logs for error messages 3. Contact the team via GitHub issues
Note: The CI workflow is already configured for Codecov. You only need to add the CODECOV_TOKEN secret to enable reporting.