Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!solaris.cc.vt.edu!news.vt.edu!newsfeed-00.mathworks.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Unit test failing please help Date: Fri, 26 Aug 2011 15:58:05 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 40 Message-ID: References: NNTP-Posting-Host: panix2.panix.com X-Trace: reader1.panix.com 1314374285 15191 166.84.1.2 (26 Aug 2011 15:58:05 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 26 Aug 2011 15:58:05 +0000 (UTC) User-Agent: nn/6.7.3 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12229 In lblake writes: > Hi I am new to python I am at bit lost as to why my unit test is > failing below is the code and the unit test: > class Centipede(object): > legs, stomach You aren't assigning any values to "legs" or "stomach" here. From your later code, it seems like you intend these items to start out as empty lists. This code might work better: class Centipede(object): legs = [] stomach = [] (In fact, since you aren't *assigning* anything to legs or stomach but you're simply *referencing them*, this code should have been an error because those names do not yet exist.) > def __init__(self): This __init__() method does nothing at all. It doesn't even have a pass statement, which means it isn't legal python. Your code should have produced an error here. > def __setattr__(self, key, value): > print("setting %s to %s" % (key, repr(value))) > if key in ([]): > self.legs.append(key) > super(Centipede, self).__setattr__(self, key,value) How will this if statement ever be true? You're checking if 'key' is a member of an empty list. -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"