mercredi 18 novembre 2015

Skipping unittest with decorator in python

I'm writing some unittest and found a rather curious behavior that nearly burned me.

The following test:

import unittest

class Test(unittest.TestCase):
    @unittest.skip('Not ready yet')
    def test_A(self):
        self.assertTrue(False)

    @unittest.skip
    def test_B(self):
        self.assertTrue(False)

    def test_C(self):
        self.assertTrue(False)

if __name__ == '__main__':
    unittest.main()

results in:

test_A (__main__.Test) ... skipped 'Not ready yet'
test_B (__main__.Test) ... ok
test_C (__main__.Test) ... FAIL

======================================================================
FAIL: test_C (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./test.py", line 13, in test_C
    self.assertTrue(False)
AssertionError: False is not true

----------------------------------------------------------------------
Ran 3 tests in 0.000s

Using the decorator unittest.skip empty does skip the test but then reports it as passed. Therefore this skipped test could be easily forgotten the next day and stay in the skip state forever. What is the reason behind this skip, but report pass behavior?

In case it matters:

  • Python: 3.4.3 | Anaconda 2.3.0 (64-bit)
  • OS: RHEL 6.7

Aucun commentaire:

Enregistrer un commentaire