fix(python): make the assert_not_equal failure message describe the failure#4778
Open
dbrattli wants to merge 1 commit into
Open
fix(python): make the assert_not_equal failure message describe the failure#4778dbrattli wants to merge 1 commit into
dbrattli wants to merge 1 commit into
Conversation
…ailure
On a failing Assert.NotEqual, assert_not_equal rendered "Expected: 1 - Actual: 1"
-- the two values are equal, which is *why* it failed, so the message reads as a
passing assertion and tells you nothing. Say what was actually expected instead:
a value other than this one.
xUnit, which the same tests run against on .NET, distinguishes the two cases for
this reason ("Assert.NotEqual() Failure: Values are equal / Expected: Not 1").
The Beam target already words it this way; JS has the same wart but is left alone
here, pending a maintainer decision.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Python Type Checking Results (Pyright)
Excluded files with errors (4 files)These files have known type errors and are excluded from CI. Remove from
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #4776, where the same wart surfaced on the Beam target.
On a failing
Assert.NotEqual,assert_not_equalrenders:The two values being equal is precisely why the assertion failed, so the message describes a passing assertion. Staring at a red test, it tells you nothing — and it briefly reads as though the test framework is broken. It happens because
assert_equalandassert_not_equalshare one format string:Now it says what was actually expected — some value other than this one:
Prior art
xUnit, which these same tests run against on .NET before being transpiled, goes out of its way to distinguish the two cases:
The Beam target already words it this way (#4775). This brings Python into line, keeping the Fable house format (
Expected... - Actual...) rather than adopting xUnit's layout.Scope: JS is deliberately left alone
fable-library-ts'sUtil.ts:assertNotEqualhas the identical wart. I have not touched it — that's a call for the JS/TS maintainers, and I'd rather use this PR to ask than to unilaterally change a message on the most-used target.@fable-compiler maintainers: do you want the same one-line change on JS/TS (and Dart/Rust, which don't currently implement
Assertat all), so all targets agree? Happy to fold it in here or leave it for a separate PR — or to drop this one if you'd rather all targets keep matching each other, warts and all.Compatibility
fable-library-pyis on PyPI and must stay backward-compatible within a minor version. This changes no signature, no raising behaviour, and no return value — only the human-readable text of a message that, by construction, is produced only on an already-failing assertion. Nothing in the repo depends on the old wording. Flagging it explicitly since AGENTS.md asks for care with the semantics of existingfable-library-pyfunctions.Tests
New
src/fable-library-py/tests/test_assert.pycovers both functions: pass, fail, and custom-message paths. The not-equal message test fails onmainand passes here; the rest pass either way.Full
fable-library-pysuite: 444 passed. Pyright clean on both files.🤖 Generated with Claude Code