[issue35687] The unittest module diff is missing/forgetting/not putting newline before + and ? for some inputs

Addons Zz report at bugs.python.org
Wed Jan 9 05:50:33 EST 2019


Addons Zz <addonszz at outlook.com> added the comment:

The issue is also reproducible, by directly using difflib:
```python
import difflib

def bugged_diff(expected, actual):
    expected = expected.splitlines( 1 )
    actual = actual.splitlines( 1 )

    # diff = difflib.ndiff( expected, actual )
    if expected != actual:
        diff = difflib.context_diff( expected, actual, fromfile='expected input', tofile='actual output', lineterm='\n' )
        return '\n' + ''.join( diff )


if __name__ == '__main__':
    expected = "testing.main_unit_tests.test_dictionaryBasicLogging:416 - dictionary\n" \
            "testing.main_unit_tests.test_dictionaryBasicLogging:417 - dictionary {1: 'defined_chunk'}"

    actual = "15:49:35:912.348986 - testing.main_unit_tests - dictionary\n" \
            "15:49:35:918.879986 - testing.main_unit_tests - dictionary {1: 'defined_chunk'}"

    print( expected, actual )
```

It outputs:
```
testing.main_unit_tests.test_dictionaryBasicLogging:416 - dictionary
testing.main_unit_tests.test_dictionaryBasicLogging:417 - dictionary {1: 'defined_chunk'} 15:49:35:912.348986 - testing.main_unit_tests - dictionary
15:49:35:918.879986 - testing.main_unit_tests - dictionary {1: 'defined_chunk'}
```

But it should be: (still missing the new line on the same place as `assertEqual` does)
```
testing.main_unit_tests.test_dictionaryBasicLogging:416 - dictionary
testing.main_unit_tests.test_dictionaryBasicLogging:417 - dictionary {1: 'defined_chunk'} 
15:49:35:912.348986 - testing.main_unit_tests - dictionary
15:49:35:918.879986 - testing.main_unit_tests - dictionary {1: 'defined_chunk'}
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35687>
_______________________________________


More information about the Python-bugs-list mailing list