Skip to content

Improve test failure output for assertEqual#4807

Merged
boegel merged 5 commits intoeasybuilders:5.0.xfrom
Flamefire:improve_assert_output
Mar 16, 2025
Merged

Improve test failure output for assertEqual#4807
boegel merged 5 commits intoeasybuilders:5.0.xfrom
Flamefire:improve_assert_output

Conversation

@Flamefire
Copy link
Copy Markdown
Contributor

Improve the readability when a test fails:

  • The DIFF: message had an off-by-one error that missed the last line of the diff
  • When raising our enhanced failure message we included the original stacktrace as "During handling of the above exception, another exception occurred: [...]" added by Python and the string "AssertionError" by the formatting of the original message which is just noise.
  • There is no need for a DIFF for numbers, True/False/None or single-line strings as the diff is trivial and already contained as a != b, so don't do our custom handling there
  • Also a small refactoring converting "loop x: if x not in list then add to list" to a set using a generator

`range(start, stop)` does NOT include `stop` so `len() - 1` misses the last element
`"%s" % e` yields f"AssertionError({str(e)})" so just use "%s" % str(e)
Doesn't provide additonal information and makes the output more
confusing.
Currently the re-raising shows the original assertion failure inside
unittest code and then "During handling of the above exception, another exception occurred:"
and our assertion error.
Supress the former
Avoids performance penalty on every test
@boegel boegel added this to the 5.0 milestone Mar 16, 2025
@boegel boegel merged commit 50a3282 into easybuilders:5.0.x Mar 16, 2025
37 checks passed
@Flamefire Flamefire deleted the improve_assert_output branch March 17, 2025 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants