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

custom pytest_assertrepr_compare #16

Open
samuelcolvin opened this issue Feb 25, 2022 · 3 comments
Open

custom pytest_assertrepr_compare #16

samuelcolvin opened this issue Feb 25, 2022 · 3 comments

Comments

@samuelcolvin
Copy link
Owner

Approach:

  • new method on some types, e.g. __inequality_details__(op) should return a list of strings
  • add a utility function to check for __inequality_details__ and call it if required,
  • instructions on calling that function from pytest_assertrepr_compare

rough prototype for Contains:

def pytest_assertrepr_compare(config, op, left, right):
    if isinstance(right, Contains):
        word = 'not' if op == '==' else 'unexpectedly'
        if len(right.contained_values) == 1:
            descr = f'Container: {right.contained_values[0]!r} {word} found in'
        else:
            descr = f'Container: {right.contained_values!r} all {word} found in'
        return [
            f'[dirty-equals] "{op}" failed',
            descr,
            *pformat(left).split('\n'),
        ]
@osintalex
Copy link
Contributor

Any interest in me taking a crack at this?

@samuelcolvin
Copy link
Owner Author

I think best to leave it, I have some pretty strong ideas about how to go about it and it might require changes to other libraries to make it work.

@RonnyPfannschmidt
Copy link

while taking a look at some details, i took note that hamcrest implement a lot of the description stuff as well as a actual equals mapper

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

No branches or pull requests

3 participants