Unit testing errors (testing the platform module)

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Apr 14 04:09:54 EDT 2010

En Tue, 13 Apr 2010 11:01:19 -0300, John Maclean <jayeola at gmail.com>  

> Is there an error in my syntax? Why is my test failing? Line 16.
> ======================================================================
> FAIL: platform.__builtins__.blah
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "stfu/testing/test_pyfactor.py", line 16, in testplatformbuiltins
>     self.assertEquals(platform.__builtins__.__class__, "<type 'dict'>")
> AssertionError: <type 'dict'> != "<type 'dict'>"
> ----------------------------------------------------------------------

To express the condition "SOMEOBJECT must be a dictionary", use:

     isinstance(SOMEOBJECT, dict)

SOMEOBJECT might actually be an instance of any derived class and still  
pass the test; that's usually the desired behavior.

In the rare cases where only a very specific type is allowed, use this  
form instead:

     type(SOMEOBJECT) is dict

The test case above should read then:

     self.assert_(isinstance(platform.__builtins__, dict),

Gabriel Genellina

More information about the Python-list mailing list