Add remaining tests for coverage#876
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a large “gap-filling” test module intended to drive branch coverage to 100% (Issue #660), plus a few targeted # pragma: no cover annotations for paths considered unreachable or impractical to hit.
Changes:
- Added
test_missing_coverage.pywith many targeted tests for previously-uncovered branches across managers, query/translation, formsets, showfields, and contrib integrations. - Marked a few specific lines as excluded from coverage via
# pragma: no cover. - Added/expanded tests for edge cases (e.g., stale content types, deferred loading translation errors, optional contrib modules).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/polymorphic/utils.py |
Adds # pragma: no cover to the (effectively unreachable) final return in _compare_mro. |
src/polymorphic/tests/test_missing_coverage.py |
New comprehensive “coverage completion” test suite targeting specific uncovered branches, including contrib integrations. |
src/polymorphic/showfields.py |
Adds # pragma: no cover to the diamond-inheritance deduplication guard branch. |
src/polymorphic/formsets/models.py |
Adds # pragma: no cover to a queryset-data model selection line in _construct_form. |
Comments suppressed due to low confidence (1)
src/polymorphic/tests/test_missing_coverage.py:1872
- This test currently ends right after calling
s.is_valid()and doesn’t assert the expected outcome or any observable effect of thehasattr(self, "_validated_data")false branch. Add assertions (e.g., thatresultisTrue/Falseas intended, and that_validated_datais absent/not updated while errors are still propagated) so the branch is actually verified rather than just executed opportunistically.
with mock.patch.object(drf_serializers.Serializer, "is_valid", patched_is_valid):
result = s.is_valid()
# Result depends on child validation (child is valid, so True)
# But _validated_data was deleted before the check, so branch 98->101 executes
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| with patch.object(ContentType.objects, "get_for_id", side_effect=patched_get_for_id): | ||
| result = qs._get_real_instances([b_obj]) | ||
| # With None model class, object ends up as None in resultlist and gets filtered out | ||
|
|
There was a problem hiding this comment.
test_real_concrete_class_is_none doesn’t assert anything about the result or side effects (it exits the patch context without checks), so it won’t fail even if the targeted branch regresses or isn’t executed. Add at least one assertion that verifies the expected behavior (e.g., returned list is empty and/or no exception is raised) to make this a meaningful regression test.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #876 +/- ##
==========================================
+ Coverage 95.78% 99.10% +3.32%
==========================================
Files 28 28
Lines 1896 1892 -4
Branches 273 270 -3
==========================================
+ Hits 1816 1875 +59
+ Misses 48 12 -36
+ Partials 32 5 -27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 6 files with indirect coverage changes 🚀 New features to boost your workflow:
|
closes #660