Skip to content

Instantly share code, notes, and snippets.

@behrtam
Created November 25, 2015 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save behrtam/3fe4c75bcee4a02c5953 to your computer and use it in GitHub Desktop.
Save behrtam/3fe4c75bcee4a02c5953 to your computer and use it in GitHub Desktop.
"This method is used by default when comparing strings with assertEqual()." https://docs.python.org/2/library/unittest.html?highlight=unittest#unittest.TestCase.assertMultiLineEqual
import unittest
class AssertTests(unittest.TestCase):
def testAssertEqual(self):
self.assertEqual('ABCD', 'ABC')
def testAssertMultiLineEqual(self):
self.assertMultiLineEqual('ABCD', 'ABC')
if __name__ == '__main__':
unittest.main()
''' # OUTPUT
$ python2.7 asserttest.py
FF
======================================================================
FAIL: test_one (__main__.AssertTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "asserttest.py", line 6, in test_one
self.assertEqual('ABCD', 'ABC')
AssertionError: 'ABCD' != 'ABC'
======================================================================
FAIL: test_transcribes_all_occurences (__main__.AssertTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "asserttest.py", line 9, in test_transcribes_all_occurences
self.assertMultiLineEqual('ABCD', 'ABC')
AssertionError: 'ABCD' != 'ABC'
- ABCD
? -
+ ABC
----------------------------------------------------------------------
Ran 2 tests in 0.001s
FAILED (failures=2)
$ python3.5 asserttest.py
FF
======================================================================
FAIL: test_one (__main__.AssertTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "asserttest.py", line 6, in test_one
self.assertEqual('ABCD', 'ABC')
AssertionError: 'ABCD' != 'ABC'
- ABCD
? -
+ ABC
======================================================================
FAIL: test_transcribes_all_occurences (__main__.AssertTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "asserttest.py", line 9, in test_transcribes_all_occurences
self.assertMultiLineEqual('ABCD', 'ABC')
AssertionError: 'ABCD' != 'ABC'
- ABCD
? -
+ ABC
----------------------------------------------------------------------
Ran 2 tests in 0.001s
FAILED (failures=2)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment