confused by bindings

Sam Falkner samf+usenet at frii.com
Wed Sep 19 18:05:12 CEST 2001


I'm confused.  I'm a relative newbie, but am still surprised that I
can't make this work.

What I want to do is to have my test module set "stuff" in one of the
other modules, do its tests, and then check the results.  Code might
be more clear:

--- file data.py ---

class Cell:
    count = 0
    def __init__(self, stuff):
        self.count += 1
        self.stuff = stuff
        print 'count is', self.count

--- file test.py ---

class CellTestCase(unittest.TestCase):
    def testforleaks(self):
        data.Cell.count = 0
        # do a whole bunch of stuff
        # x = a gnarly collection of Cell objects
        # count number of Cell objects in x
        self.failUnlessEqual(count-of-Cells-from-x, data.Cell.count)

In other words, I'm trying to test for a leak of Cell objects.  But,
no matter what I've tried, this doesn't work.  I've tried
global-to-the-data-module variables for the count, I've tried the Borg 
pattern from the cookbook, but nothing works.

When I run it this way, I get
count is 1
count is 1
count is 1
count is 1
...

and the test fails with 5499 != 0.

Okay, I feel stupid here.  What am I doing wrong?

Thanks!

- Sam



More information about the Python-list mailing list