8000 Fix chaining failure in `raises` soft assertion (#130) by betapl3b · Pull Request #131 · assertpy/assertpy · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@betapl3b
Copy link

Please have a look at this bug:
#130

This PR prevents program from failing in described scenarios. It replaces all callable attributes of AssertionBuilder instance with some empty function that returns self. So any chaining assertion of current AssertionBuilder instance will be ignored and won't cause failures.

Also it notifies users about about ignoring any further chaining assertions.

Example:

with assertpy.soft_assertions():
    # No exception
    assertpy.assert_that(lambda x: 1/x).raises(ZeroDivisionError).when_called_with(1).is_equal_to('dog').matches('cat')
    # Exception type mismatch
    assertpy.assert_that({}.__getitem__).raises(RuntimeError).when_called_with('a').contains('dog')
    # Error message mismatch
    assertpy.assert_that(lambda x: 1/x).raises(ZeroDivisionError).when_called_with(0).matches('dog')

Output:

AssertionError: soft assertion failures:
1. Expected <<lambda>> to raise <ZeroDivisionError> when called with (1). Any further chain assertions ignored.
2. Expected <__getitem__> to raise <RuntimeError> when called with ('a'), but raised <KeyError>. Any further chain assertions ignored.
3. Expected <division by zero> to match pattern <dog>, but did not.

@betapl3b betapl3b changed the title Fix chaining failure in raises soft assertion (#130) Fix chaining failure in raises soft assertion (https://github.com/assertpy/assertpy/issues/130) Mar 14, 2023
@betapl3b betapl3b changed the title Fix chaining failure in raises soft assertion (https://github.com/assertpy/assertpy/issues/130) Fix chaining failure in raises soft assertion (#130) Mar 14, 2023
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

0