classification
Title: Reversed order in testtools messages
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.3, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, zaitcev
Priority: normal Keywords:

Created on 2014-02-27 16:40 by zaitcev, last changed 2014-02-27 19:58 by r.david.murray. This issue is now closed.

Messages (3)
msg212366 - (view) Author: Pete Zaitcev (zaitcev) Date: 2014-02-27 16:40
When using an assert such as self.assertEquals(tester(), expected), an error message suggests wrong argument order (as in, not the order in examples in the documentation). Apparently this is confusing enough that OpenStack even opened a whole bunch of bugs and filed patches to swap the order in the tests:
 https://bugs.launchpad.net/ceilometer/+bug/1277104

If the code is:

import testtools

class TestConfigTrueValue(testtools.TestCase):
    def test_testEquals(self):
        reference = "reference-0123456789012345678901234567890123456789"
        def function_under_test():
            return "actual-0123456789012345678901234567890123456789"
        self.assertEquals(function_under_test(), reference)

then running it yields

[zaitcev@guren xxx]$ python3 -c 'import nose; nose.main()'
F
======================================================================
FAIL: testic.TestConfigTrueValue.test_testEquals
----------------------------------------------------------------------
testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/q/zaitcev/tmp/xxx/testic.py", line 10, in test_testEquals
    self.assertEquals(function_under_test(), reference)
  File "/usr/lib/python3.3/site-packages/testtools/testcase.py", line 322, in assertEqual
    self.assertThat(observed, matcher, message)
  File "/usr/lib/python3.3/site-packages/testtools/testcase.py", line 417, in assertThat
    raise MismatchError(matchee, matcher, mismatch, verbose)
testtools.matchers._impl.MismatchError: !=:
reference = 'actual-0123456789012345678901234567890123456789'
actual    = 'reference-0123456789012345678901234567890123456789'
msg212368 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-02-27 16:51
Testtools is not part of the stdlib.  Are you saying there is a bug in the stdlib assertEqual?  If so, can you demonstrate the bug using just stdlib-based code?
msg212379 - (view) Author: Pete Zaitcev (zaitcev) Date: 2014-02-27 19:46
Oh, indeed. The printout is in testtools only. The unittest prints this:

[zaitcev@guren xxx]$ python3 -c 'import nose; nose.main()'
F
======================================================================
FAIL: test_testEquals (testic.TestConfigTrueValue)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/q/zaitcev/tmp/xxx/testic.py", line 11, in test_testEquals
    self.assertEquals(function_under_test(), reference)
AssertionError: 'actual-0123456789012345678901234567890123456789' != 'reference-0123456789012345678901234567890123456789'
- actual-0123456789012345678901234567890123456789
? ^ ^^^^
+ reference-0123456789012345678901234567890123456789
? ^^^^^^^ ^

Sorry, closing the issue as invalid.
History
Date User Action Args
2014-02-27 19:58:02r.david.murraysetstatus: open -> closed
2014-02-27 19:46:12zaitcevsetresolution: not a bug
messages: + msg212379
2014-02-27 16:51:31r.david.murraysetnosy: + r.david.murray
messages: + msg212368
2014-02-27 16:40:42zaitcevcreate