feat: add test coverage tracking with pytest-cov#512
Conversation
- Add pytest-cov>=4.1.0 to dev dependencies - Configure coverage in pyproject.toml (run, report, html) - Integrate coverage reports into CI workflow - Update .gitignore for coverage artifacts - Document coverage usage in docs/README-DEV.md Current coverage baseline: 34.45%
Reviewer's GuideAdds pytest-cov-based coverage tracking, config, and reporting to the Python server project and CI workflow, and documents how to run and inspect coverage locally. Flow diagram for coverage configuration usage via pyproject.tomlflowchart TD
A[Developer runs pytest<br>with --cov=src<br>--cov-report=term<br>--cov-report=html] --> B[pytest loads pytest_cov plugin]
B --> C[coverage_py starts measurement]
C --> D[coverage_py reads tool.coverage.run<br>from pyproject.toml]
D --> E[Apply source=src<br>and omit patterns<br>for tests]
E --> F[Execute tests and record executed lines]
F --> G[Generate terminal report<br>using tool.coverage.report<br>settings]
G --> H[Generate HTML report in htmlcov<br>using tool.coverage.html settings]
H --> I[Developer views htmlcov/index.html<br>in browser]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the 📝 WalkthroughWalkthroughAdds test coverage collection and reporting: adds Changes
sequenceDiagram
autonumber
participant GH as GitHub Actions
participant Runner as CI Runner
participant Pytest as pytest (+ pytest-cov)
participant Artifacts as Artifact Store
participant Codecov as Codecov
GH->>Runner: Trigger "python-tests" workflow
Runner->>Pytest: Run tests with coverage (XML, HTML, terminal)
Pytest-->>Runner: Produce coverage.xml and htmlcov/
Runner->>Artifacts: Upload test artifacts + coverage.xml + htmlcov/
Runner->>Codecov: Upload coverage.xml via codecov-action
Codecov-->>Runner: Acknowledge upload
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
exclude_linespattern"if __name__ == .__main__.:"in[tool.coverage.report]looks misquoted and likely won't match the standardif __name__ == '__main__':guard; consider correcting it so those lines are actually excluded. - Since
[tool.coverage.run]already definessource = ["src"], you could simplify the pytest commands in CI and docs by dropping the explicit--cov=srcflag and relying on the centralized configuration instead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `exclude_lines` pattern `"if __name__ == .__main__.:"` in `[tool.coverage.report]` looks misquoted and likely won't match the standard `if __name__ == '__main__':` guard; consider correcting it so those lines are actually excluded.
- Since `[tool.coverage.run]` already defines `source = ["src"]`, you could simplify the pytest commands in CI and docs by dropping the explicit `--cov=src` flag and relying on the centralized configuration instead.
## Individual Comments
### Comment 1
<location> `Server/pyproject.toml:72` </location>
<code_context>
+ "def __repr__",
+ "raise AssertionError",
+ "raise NotImplementedError",
+ "if __name__ == .__main__.:",
+ "if TYPE_CHECKING:",
+ "@abstractmethod",
</code_context>
<issue_to_address>
**issue (bug_risk):** Coverage `exclude_lines` pattern for `__main__` guard looks malformed and likely won’t match.
The pattern `"if __name__ == .__main__.:"` is not valid syntax and won’t match real `if __name__ == "__main__":` lines, so those blocks will still count toward coverage. Please update it to a correct pattern like `"if __name__ == \"__main__\":"` (properly escaped for TOML) so main guards are excluded as intended.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
msanatan
left a comment
There was a problem hiding this comment.
Looks good @Nonanti ! Can you:
- Update your branch with the latest from main. I'd recommend accepting the new uv.lock for the merge conflict, and then creating a brand new
- Can you update the Simple Chinese translation of the dev README as well? I don't speak the language, but I typically as ChatGPT to do it for me
|
By chance @Nonanti, do you have example output of the coverage on your fork? |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
Server/pyproject.toml (1)
45-45: Consider exact version pinning for consistency.While
pytest-cov>=4.1.0works, consider using exact version pinning (e.g.,pytest-cov==4.1.0) to match the approach used forfastmcp==2.14.1on line 33. This prevents potential breaking changes from minor version updates during development.Based on learnings, exact version pinning is preferred to prevent breaking changes.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Server/uv.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
.gitignoreServer/pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (1)
- .gitignore
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-29T04:54:17.743Z
Learnt from: dsarno
Repo: CoplayDev/unity-mcp PR: 490
File: Server/pyproject.toml:33-33
Timestamp: 2025-12-29T04:54:17.743Z
Learning: Pin the fastmcp dependency to an exact version in Server/pyproject.toml (e.g., exact string 2.14.1). Avoid range pins like >=2.13.0 to prevent breaking changes affecting MCP tools. Apply the same exact-version pinning approach according to the syntax of the package tool in use (e.g., Poetry: fastmcp = '2.14.1' or equivalent exact-specifier).
Applied to files:
Server/pyproject.toml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Sourcery review
🔇 Additional comments (2)
Server/pyproject.toml (2)
66-77: LGTM!The coverage report configuration follows pytest-cov best practices. The
exclude_linespatterns appropriately exclude defensive code, type-checking blocks, and abstract methods that don't need coverage. Theprecision = 2andshow_missing = truesettings provide clear, actionable coverage reports.
79-80: LGTM!Using
htmlcovas the output directory for HTML coverage reports is the standard convention for pytest-cov, making it familiar to developers and consistent with documentation examples.
|
Thanks @Nonanti ! Inspiring me to do this for the c# code too, so I installed Unity's Code Coverage package in the Test Project to test it. See results below. Good stuff. We should add this @msanatan @Scriptwonder -- 33% is a decent start but we should cover the whole dang thing. MCP for Unity Code Coverage C#
|
|
@dsarno This is really interesting. |

Add pytest-cov>=4.1.0 to dev dependencies
Current coverage baseline: 34.45%
Summary by Sourcery
Add code coverage tracking and reporting to the Python test workflow.
New Features:
Enhancements:
CI:
Documentation:
Summary by CodeRabbit
Chores
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.