Skip to content

Refs #35728 -- Added standard failure prefixes to assertion message tests. #19588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cliff688
Copy link
Member

@cliff688 cliff688 commented Jun 24, 2025

Trac ticket number

Two additional commits I added while working on this:

  1. Splitting monolithic test_contains() test into smaller focused tests (10+)
  2. Adding missing tests for assertRedirects when following redirect chains.

ticket-35728

cliff688 added 3 commits June 24, 2025 21:44
…ing assertRaisesMessage.

Also added standard unittest-inherited prefixes (e.g. "1 != 2 : ") to expected
error messages.

Refs #36280.
"(expected 302)",
str(e),

def test_followed_redirect_unexpected_initial_status_code(self):
Copy link
Member Author

@cliff688 cliff688 Jun 24, 2025

Choose a reason for hiding this comment

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

I could remove the assertions:

self.assertEqual(
response.redirect_chain[0][1],
status_code,
msg_prefix
+ (
"Initial response didn't redirect as expected: Response code was "
"%d (expected %d)"
)
% (response.redirect_chain[0][1], status_code),
)
and
self.assertEqual(
response.status_code,
target_status_code,
msg_prefix
+ (
"Response didn't redirect as expected: Final Response code was %d "
"(expected %d)"
)
% (response.status_code, target_status_code),
)
without any test failures.

@cliff688
Copy link
Member Author

Marking as draft as the unittest assertion messages may be dropped pending discussion in #19402 (review).

As it currently stands, here are the reasons why we may not need to keep (or test) the message prefixes from unittest:

  1. There's no compelling reason to keep the messages as is, since, as Sarah points out, in the linked review) it is unlikely that anyone depends on these messages, and as Simon pointed out, we don't offer any strong guarantees that error messages will remain the same.
  2. Preserving the message prefixes when using self.fail() adds a bit of boilerplate to the assertion messages.
    (3. TIL testing error message too closely may be brittle.)

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.

1 participant