Commits

Ned Batchelder committed 13bc67c

imported patch multiline-msg

  • Participants
  • Parent commits 9a8e964

Comments (0)

Files changed (2)

test/backunittest.py

                 raise self.failureException("%r doesn't match %r" % (s, regex))
 
     if _need('assertMultiLineEqual'):
-        def assertMultiLineEqual(self, first, second):
+        def assertMultiLineEqual(self, first, second, msg=None):
             """Assert that two multi-line strings are equal.
 
             If they aren't, show a nice diff.
                     'Second argument is not a string')
 
             if first != second:
-                msg = ''.join(difflib.ndiff(first.splitlines(True),
+                message = ''.join(difflib.ndiff(first.splitlines(True),
                                                     second.splitlines(True)))
-                self.fail("Multi-line strings are unequal:\n" + msg)
+                if msg:
+                    message += " : " + msg
+                self.fail("Multi-line strings are unequal:\n" + message)

test/test_testing.py

         self.assertRaises(AssertionError, self.assertMultiLineEqual,
             "hello\nthere", "hello\nThere"
             )
+        # With messages also.
+        self.assertMultiLineEqual("hi", "hi", "it's ok")
+        self.assertRaisesRegexp(
+            AssertionError, "my message",
+            self.assertMultiLineEqual, "xyz", "abc", "my message"
+        )
 
     def test_assert_raises_regexp(self):
         # Raising the right error with the right message passes.