help: Unit test fixture returning the same object

Roy Smith roy at
Wed Aug 4 03:03:45 CEST 2004

In article <9895e897.0408031533.26720ba0 at>,
 michael_mccracken at (Michael McCracken) wrote:

> The problem is that in each test case, setUp and tearDown are called
> as expected according to the print statements, but they don't seem to
> have any effect after the first invocation. self.testfile is always
> the same instance as reported by id().

Are you really sure they're the same object?  id() just returns the 
address of the object in memory.  It's possible for two objects to have 
the same id as long as their lifetimes never overlap.  If you repeatedly 
create and destroy the same type of objects in the same context (as 
happens in a unittest environment), it's reasonably likely that objects 
will reuse the same memory locations.

Other than the oddity of id() returning the same value in different 
tests, is something unexpected happening?

More information about the Python-list mailing list