Help with unittest2

Thomas Bach thbach at
Thu Dec 13 17:04:15 CET 2012


On Thu, Dec 13, 2012 at 07:03:27AM -0800, Daniel Laird wrote:
> I do am import unittest2 as unittest
> The code does not fail but any use of the new functions results in:
> NameError: global name 'assertListEqual' is not defined
> What am I doing wrong?

Read the error message again: it says that it cannot find the _global_
name 'assertListEqual'!

assertListEqual is a method of unittest.TestCase. Hence, it has to be
called on a unittest.TestCase instance, such as

import unittest

class FooTests(unittest.TestCase):

    def test_a_list(self):
        a = ['foo', 'bar']
	b = ['foo', 'bar']
	self.assertListEqual(a, b)

BTW, I actually never used 'assertTypeEqual'. I rather call
assertEqual and let unittest do the internals. I think assertEqual
calls the right method for you depending on the arguments type. If you
want to make sure that something is of a certain type use

Hope this helps,

     Thomas Bach.

More information about the Python-list mailing list