conftest.py 492 B

123456789101112131415161718
  1. import difflib
  2. def iter_diff(fr, to):
  3. for line in difflib.unified_diff(fr.splitlines(), to.splitlines(), fromfile='L', tofile='R'):
  4. line = line.rstrip('\n')
  5. if line:
  6. if line[0] == '-':
  7. line = '[[bad]]' + line + '[[rst]]'
  8. elif line[0] == '+':
  9. line = '[[good]]' + line + '[[rst]]'
  10. yield line
  11. def pytest_assertrepr_compare(op, left, right):
  12. return ['failed, show diff'] + list(iter_diff(left, right))