dirty-equals
dirty-equals copied to clipboard
custom `pytest_assertrepr_compare`
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'),
]
Any interest in me taking a crack at this?
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.