aboutsummaryrefslogblamecommitdiffstats
path: root/library/python/cpp_test/conftest.py
blob: 5e9a0fbf9a9c2722392a1e8c406615292be573b5 (plain) (tree)
1
2
3
4
5
6
7


                      
                                                                                                 
 



                                                    
 
                  


                                                               
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))