[Python-Dev] r87389 - in python/branches/py3k: Doc/library/unittest.rst Lib/unittest/case.py Misc/NEWS (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Tue Dec 21 02:57:50 CET 2010


On Tue, Dec 21, 2010 at 1:31 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:

Diffing is completely an implementation detail of how the failure messages are generated. The important thing is that failure messages make sense with respect to actual result and expected result. Which, again, they don't. Let's see:  self.assertEqual(actual, expected) AssertionError: 'a\nb\nc\ne\n' != 'a\nb\nc\nd\n'  a  b  c - e + d The diff shows "expected - actual", but it would be logical (in your own logic) to display "actual - expected". The whole issue disappears if you drop this idea of naming the arguments "actual" and "expected".

To make this a bit clearer...

class Ex(ut.TestCase): ... def demo(self): ... self.assertEqual("actual", "expected") ... Ex("demo").demo() Traceback (most recent call last): AssertionError: 'actual' != 'expected'

For the actual/expected terminology the diff is the wrong way around (as of 3.2b1, anyway).

My own +1 goes to keeping the actual/expected terminology (and ordering) and adjusting the diffs accordingly (with a header noting that the diff is old=expected, new=actual).

assertRaises() is an exception to the general actual/expected pattern, but that asymmetry is forced by the ability to pass arbitrary positional arguments to the function being tested (which later proved useful for the context manager form as well).

Cheers, Nick.

-- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-Dev mailing list