dirty-equals icon indicating copy to clipboard operation
dirty-equals copied to clipboard

custom `pytest_assertrepr_compare`

Open samuelcolvin opened this issue 3 years ago • 3 comments

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'),
        ]

samuelcolvin avatar Feb 25 '22 15:02 samuelcolvin

Any interest in me taking a crack at this?

osintalex avatar Apr 02 '22 12:04 osintalex

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.

samuelcolvin avatar Apr 02 '22 12:04 samuelcolvin