Skip to content

fix: add messages to functional assertions - #151

Closed
SwetaKumari7 wants to merge 1 commit into
abhiksark:devfrom
SwetaKumari7:improve-assertion-messages
Closed

SwetaKumari7 wants to merge 1 commit into
abhiksark:devfrom
SwetaKumari7:improve-assertion-messages

Conversation

@SwetaKumari7

@SwetaKumari7 SwetaKumari7 commented Sep 18, 2026 •

Copy link
Copy Markdown

Summary

  • Add actionable messages to all previously bare assertions in functional checks.
  • Include the actual value where useful.
  • Preserve the existing assertion predicates, order, helper statements, and success output.

Verification

  • python -m pytest tests/integration/test_solution_verify.py -q
  • pythonlings --root tests/fixtures/passing_curriculum verify
  • AST audit confirms 0 bare assertions across functional1.py through functional6.py.
  • git diff --check passes.

Closes #86

Thank you for reviewing this contribution. Any feedback or suggestions are welcome.

Summary by CodeRabbit

  • Tests
    • Improved functional test failure messages with clearer details about expected and actual values and types.
    • Enhanced boundary and lambda test diagnostics without changing validation logic or expected results.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0e123eb8-3212-4cc7-a4ca-a57bdbf54902
📥 Commits

Reviewing files that changed from the base of the PR and between 7bd85bf and 9160845.

📒 Files selected for processing: 6
  • checks/functional/functional1.py
  • checks/functional/functional2.py
  • checks/functional/functional3.py
  • checks/functional/functional4.py
  • checks/functional/functional5.py
  • checks/functional/functional6.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
🧰 Additional context used
📚 Code guidelines: 1
AGENTS.md — unknown
📓 Path-based instructions: 3
Maintain Python 3.9 compatibility.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • checks/functional/functional1.py
  • checks/functional/functional3.py
  • checks/functional/functional2.py
  • checks/functional/functional6.py
  • checks/functional/functional4.py
  • checks/functional/functional5.py
Preserve learner-edited exercises during workspace updates.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • checks/functional/functional1.py
  • checks/functional/functional3.py
  • checks/functional/functional2.py
  • checks/functional/functional6.py
  • checks/functional/functional4.py
  • checks/functional/functional5.py
Checks must use bare assertions with actionable, beginner-facing messages.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • checks/functional/functional1.py
  • checks/functional/functional3.py
  • checks/functional/functional2.py
  • checks/functional/functional6.py
  • checks/functional/functional4.py
  • checks/functional/functional5.py
🪛 Ruff (0.16.10)
checks/functional/functional1.py

[error] 3-3: Undefined name square

(F821)

checks/functional/functional3.py

[error] 2-2: Undefined name doubled

(F821)

checks/functional/functional2.py

[error] 3-3: Undefined name absolute

(F821)

[error] 4-4: Undefined name absolute

(F821)

checks/functional/functional6.py

[error] 7-7: Undefined name apply_twice

(F821)

[error] 9-9: Undefined name apply_twice

(F821)

checks/functional/functional4.py

[error] 2-2: Undefined name evens

(F821)

[error] 3-3: Undefined name evens

(F821)

checks/functional/functional5.py

[error] 4-4: Undefined name by_length

(F821)

[error] 5-5: Undefined name by_length

(F821)

🔇 Additional comments: 6
checks/functional/functional1.py: 1

3-3: LGTM!

checks/functional/functional2.py: 1

3-4: LGTM!

checks/functional/functional3.py: 1

2-2: LGTM!

checks/functional/functional4.py: 1

2-4: LGTM!

checks/functional/functional5.py: 1

4-6: LGTM!

checks/functional/functional6.py: 1

7-11: LGTM!

📝 Walkthrough

Six functional check files now provide diagnostic messages when assertions fail. The assertions retain their existing checks and expected results.

Changes: Functional check diagnostics

Layer / File(s) Summary
Assertion failure messages
checks/functional/functional1.py, checks/functional/functional2.py, checks/functional/functional3.py, checks/functional/functional4.py, checks/functional/functional5.py, checks/functional/functional6.py
Assertions now report expected behavior or values when they fail. The checks and success output remain unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other · Severity of issue fixed: Low

Suggested reviewers: abhiksark

Merge Risk: ⚪ Minimal · up to 91608

The change improves failure diagnostics without altering functional check behavior.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #86 requires nine non-empty, actionable messages, unchanged predicates and order, unchanged side effects and success output, Python 3.9 compatibility, and passing verification for all 292 refere… Provide evidence from python -m pytest -q and verification of all 292 reference answers. The current evidence does not establish those acceptance criteria.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: adding messages to functional assertions.
Description check Passed The description explains the change, lists verification commands and audits, and references the related issue. It uses a "Verification" heading instead of the template's "Tests" heading and omits the …
Out of Scope Changes check Passed The complete merge-base-to-head diff changes only checks/functional/functional1.py through checks/functional/functional6.py, which are the six files listed by issue #86. The changes add assertion …
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 6…
Full details: Description check

Explanation

The description explains the change, lists verification commands and audits, and references the related issue. It uses a "Verification" heading instead of the template's "Tests" heading and omits the "Screenshots" and "Checklist" sections, but it provides the key implementation and testing information.

Full details: Out of Scope Changes check

Explanation

The complete merge-base-to-head diff changes only checks/functional/functional1.py through checks/functional/functional6.py, which are the six files listed by issue #86. The changes add assertion messages and do not modify exercises, solutions, hints, URLs, manifest order, names, or curriculum semantics.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 6 files.

Full details: Linked Issues check

Explanation

Issue #86 requires nine non-empty, actionable messages, unchanged predicates and order, unchanged side effects and success output, Python 3.9 compatibility, and passing verification for all 292 reference answers. The complete diff shows messages on all nine assertions in the six listed files. It also preserves the assertion expressions, order, and print statements. The added syntax is Python 3.9 compatible. The reported verification covers the integration test and passing curriculum fixture, but it does not establish that all 292 reference answers and the full required test suite pass.

Resolution

Provide evidence from python -m pytest -q and verification of all 292 reference answers. The current evidence does not establish those acceptance criteria.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

A rabbit checks each test with care,
Clear messages wait when things go wrong.
The expected values now appear,
The checks still follow their original song.
The rabbit hops along, content.

Comment @coderabbitai help to get the list of available commands.

@SwetaKumari7

Copy link
Copy Markdown
Author

@coderabbitai review

Hi, could you please review this PR when you get a chance? I've added actionable messages to the functional assertions while preserving the existing assertion logic and order. Thank you for your time and feedback!

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@abhiksark abhiksark left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not ready to merge at 9160845. Four added message expressions re-run learner code: square(0), absolute(0), absolute(-100), and apply_twice(..., 0). All four were reproduced with a side-effecting failing learner function; the message masks the original assertion with RuntimeError. Please use expected-value messages without re-evaluation and add regression coverage.

The head branch is also improve-assertion-messages; the repository requires a fix/ or feature/ branch targeting dev. Please use a compliant branch and apply the file-location-comment and 80-column conventions. After correcting these issues, record the required full-suite, fixture-verification, and packaging checks and obtain passing CI. Issue #86 remains open. Full build/runtime validation was not repeated here because the reproduced message defect and branch-policy mismatch already block merging.

assert square(3) == 9, f"square(3) should be 9, got {square(3)}"
assert square(5) == 25, f"square(5) should be 25, got {square(5)}"
assert square(0) == 0
assert square(0) == 0, f"square(0) should be 0, got {square(0)}"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[P2] Do not call the learner's function again in the failure message.

The new square(0) message evaluates square(0) a second time. I reproduced this with a learner function that returns an incorrect result on the first zero call and raises on the second: the check reports the second call's RuntimeError instead of the expected assertion failure. This violates CONTRIBUTING.md's rule against re-calling learner functions to format messages.

Use a constant expected-value message here. The new absolute(0) and absolute(-100) messages in functional2 have the same problem. Add a focused regression using a side-effecting failing function.

print("functional6 ✓")
assert apply_twice(lambda x: x + 1, 0) == 2, (
f"apply_twice(lambda x: x + 1, 0) should be 2, "
f"got {apply_twice(lambda x: x + 1, 0)}"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[P2] Preserve the single evaluation of apply_twice.

This new failure message also calls apply_twice(...) again, including executing the learner's callback again. The same probe reproduces a RuntimeError masking the original assertion failure. Keep the original predicate and use an expected-value message that does not execute learner code.

abhiksark added a commit that referenced this pull request Nov 5, 2026
Complete #151 with all nine expected-value messages while preserving predicates, execution order, helpers, and success output. Avoid new learner-function re-calls and cover all four failure paths.

Closes #86.

Co-authored-by: Sweta Kumari <wbswetakumari@gmail.com>
@abhiksark

Copy link
Copy Markdown
Owner

Completed with contributor credit in #169, now squash-merged into dev as 154a4e626b4111c06e6b03d656e3f0e3bed45ca1. The replacement starts from current dev on a compliant fix/ branch, removes the four new learner-function re-calls, and adds four regressions proved against this PR's faulty behavior. All 253 tests, curriculum verification, source/wheel validation, and eight CI jobs passed. Closing this original PR as superseded.

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.

2 participants