Skip to content
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

Better handling for exception messages with special characters #226

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

tallus
Copy link

@tallus tallus commented Mar 3, 2023

raises(Error, "message with (parens)") no longer fails with an exact match

def raise_error():
    raise AssertionError("Message with  (parens)")

assert_that(calling(raise_error),  raises(AssertionError, "Message with (parens)")
```
will fail with `Correct assertion type raised, but the expected pattern ("Message with (parens)") not found. Exception message was: "Message with (parens)"` which is a somewhat confusing message.

This is because the parens in the pattern are treated as a regex group and need to be escaped.

This pull request removes this source of potential confusion. The above code will now not error as a regex mismatch will only happen if the pattern does not match as a regex AND it is not a literal match for the error.

Paul and others added 2 commits March 3, 2023 20:46
  - raises(Error, "message with (parens)") no longer fails with an exact
    match
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