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

make assert_that user friendly on assertion errors using contains_string #235

Open
bandophahita opened this issue Jul 18, 2023 · 0 comments

Comments

@bandophahita
Copy link

bandophahita commented Jul 18, 2023

We use hamcrest in screenpy. Something I would like to request is; making the output of assertion errors a little more user friendly. When using string_contains the output is not lined up to easily see the differences between the expected and the actual.

Example:

very_long_string = """Asserts that actual value satisfies matcher. (Can also assert plain
    boolean condition.)
    :param actual: The object to evaluate as the actual value.
    :param matcher: The matcher to satisfy as the expected condition.
    :param reason: Optional explanation to include in failure description.
    ``assert_that`` passes the actual value to the matcher for evaluation. If
    the matcher is not satisfied, an exception is thrown describing the
    mismatch."""

another_long_string = """Asserts that actual value satisfies matcher. (Can also assert plain
    boolean condition.)
    :param actual: The object to evaluate as the actual value.
    :param matcher: The matcher to satisfy as the expected condition.
    :param reason: Optional explanation to include in failure description.
    ``assert_that`` passes the actual value to the matcher for evaluation. If
    the matcher is not satisfied, an exception is thrown describing the
    mismatches"""

assert_that(very_long_string, contains_string(another_long_string))

exception:

Traceback (most recent call last):
  File "/Users/me/.pyenv/versions/project/lib/python3.10/site-packages/hamcrest/core/assert_that.py", line 58, in assert_that
    _assert_match(actual=actual_or_assertion, matcher=matcher, reason=reason)
  File "/Users/me/.pyenv/versions/project/lib/python3.10/site-packages/hamcrest/core/assert_that.py", line 73, in _assert_match
    raise AssertionError(description)
AssertionError: 
Expected: a string containing 'Asserts that actual value satisfies matcher. (Can also assert plain\n    boolean condition.)\n    :param actual: The object to evaluate as the actual value.\n    :param matcher: The matcher to satisfy as the expected condition.\n    :param reason: Optional explanation to include in failure description.\n    ``assert_that`` passes the actual value to the matcher for evaluation. If\n    the matcher is not satisfied, an exception is thrown describing the\n    mismatches'
     but: was 'Asserts that actual value satisfies matcher. (Can also assert plain\n    boolean condition.)\n    :param actual: The object to evaluate as the actual value.\n    :param matcher: The matcher to satisfy as the expected condition.\n    :param reason: Optional explanation to include in failure description.\n    ``assert_that`` passes the actual value to the matcher for evaluation. If\n    the matcher is not satisfied, an exception is thrown describing the\n    mismatch.'

It would be awesome if the two strings were lined up somehow:

AssertionError: 
Expected: a string containing 'Asserts that actual value satisfies matcher. (Can also assert plain\n    boolean condition.)\n    :param actual: The object to evaluate as the actual value.\n    :param matcher: The matcher to satisfy as the expected condition.\n    :param reason: Optional explanation to include in failure description.\n    ``assert_that`` passes the actual value to the matcher for evaluation. If\n    the matcher is not satisfied, an exception is thrown describing the\n    mismatches'
     but: was                 'Asserts that actual value satisfies matcher. (Can also assert plain\n    boolean condition.)\n    :param actual: The object to evaluate as the actual value.\n    :param matcher: The matcher to satisfy as the expected condition.\n    :param reason: Optional explanation to include in failure description.\n    ``assert_that`` passes the actual value to the matcher for evaluation. If\n    the matcher is not satisfied, an exception is thrown describing the\n    mismatch.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants