Skip to content

Add remaining tests for coverage#876

Merged
bckohan merged 3 commits into
django-commons:mainfrom
bckohan:coverage_tests
May 31, 2026
Merged

Add remaining tests for coverage#876
bckohan merged 3 commits into
django-commons:mainfrom
bckohan:coverage_tests

Conversation

@bckohan

@bckohan bckohan commented Mar 9, 2026

Copy link
Copy Markdown
Member

closes #660

Copilot AI review requested due to automatic review settings March 9, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with 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 the hasattr(self, "_validated_data") false branch. Add assertions (e.g., that result is True/False as intended, and that _validated_data is 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.

Comment thread src/polymorphic/tests/test_missing_coverage.py Outdated
Comment thread src/polymorphic/tests/test_missing_coverage.py Outdated
Comment thread src/polymorphic/tests/test_missing_coverage.py Outdated
Comment on lines +599 to +602
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

Copilot AI Mar 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/polymorphic/tests/test_missing_coverage.py Outdated
@codecov

codecov Bot commented Mar 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.10%. Comparing base (fa735f2) to head (15fa061).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/polymorphic/formsets/models.py 100.00% <ø> (+6.74%) ⬆️
src/polymorphic/showfields.py 100.00% <ø> (+14.28%) ⬆️
src/polymorphic/utils.py 100.00% <ø> (+5.59%) ⬆️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bckohan bckohan merged commit 5b16d49 into django-commons:main May 31, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test coverage needs to be 100% branch

3 participants