mercredi 8 juillet 2015

Unit testing two lists and if there is a difference, print/show it

I started yesterday with unit testing in Python. I saw examples online that test with assertEqual who automatically print out the differences between both lists. However, it seems not to happen in my script. How can I obtain that?

The code below is contained in a class derived from unittest.TestCase:

def test_list_inequality(self):
    a = [1,2,3] # In my actual code this is generated by a module's function
    b = [1,2,4]

    self.assertListEqual(a, b, 'lists are inequal')

def test_list_equality(self):
    a = [1,2,3] # In my actual code this is generated by a module's function
    b = [1,2,3]

    self.assertListEqual(a ,b, 'lists are inequal')

When running this test, it results in the following output:

test_list_equality (main.EmproToolsTestCase) ... ok test_list_inequality (main.EmproToolsTestCase) ... FAIL

======================================================================

FAIL: test_list_inequality (main.EmproToolsTestCase)

Traceback (most recent call last): File "C:/some_dir/main_test.py", line 34, in test_list_inequality self.assertListEqual(a, b, 'lists are inequal') AssertionError: lists are ineaqual


Ran 2 tests in 0.001s

FAILED (failures=1)

Aucun commentaire:

Enregistrer un commentaire