[TIP] unittest2 expectedFailure

Aaron Whitehouse lists at whitehouse.kiwi.nz
Sat Aug 1 02:55:27 PDT 2015


You may remember that I posted recently about using Tox to run our
unittests against both Python 2.6 and Python 2.7.

That now seems to be working, but I'm running into difficulty with the
@unittest.expectedFailure decorator. It appears to be working as
expected in Python 2.7, but not in Python 2.6 using unittest2.

My relevant code is:

import sys

if sys.version_info < (2, 7):
    import unittest2 as unittest
    import unittest

def test_expected_failure(self):
    """Test behaviour of expectedFailure"""
    self.assertEqual(1, 2)

When I run this, it gives an expected failure on Python 2.7, but an
error on Python 2.6.
$ tox -- -s testing.unit.test_diffdir.DDTest.test_expected_failure
Test behaviour of expectedFailure ... FAIL

FAIL: Test behaviour of expectedFailure
Traceback (most recent call last):
line 139, in test_expected_failure
    self.assertEqual(1, 2)
AssertionError: 1 != 2

Ran 1 test in 0.124s

FAILED (failures=1)


Test behaviour of expectedFailure ... expected failure

Ran 1 test in 0.126s

OK (expected failures=1)
___________________________________ summary
ERROR:   py26: commands failed
  py27: commands succeeded

I thought that the intention was that these two modules acted in the
same way. Have I done something incorrectly, or have I misunderstood

Many thanks,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20150801/029b47fa/attachment.html>

More information about the testing-in-python mailing list