aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/cpp_test/conftest.py
blob: 5e9a0fbf9a9c2722392a1e8c406615292be573b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import difflib


def iter_diff(fr, to):
    for line in difflib.unified_diff(fr.splitlines(), to.splitlines(), fromfile='L', tofile='R'):
        line = line.rstrip('\n')

        if line:
            if line[0] == '-':
                line = '[[bad]]' + line + '[[rst]]'
            elif line[0] == '+':
                line = '[[good]]' + line + '[[rst]]'

        yield line


def pytest_assertrepr_compare(op, left, right):
    return ['failed, show diff'] + list(iter_diff(left, right))