[CentralOH] Not So Strange Class Behavior

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Thu Feb 6 16:46:00 CET 2014


On Thu, 6 Feb 2014 09:54:55 -0500, Joshua Kramer <joskra42.list at gmail.com> wrote:

> I'm writing a testing utility.  

Reinventing the wheel for fun? 

> I have an odd problem with properly
> dereferencing objects within a class. 

> 1. A file called sql_cases.py, with this:

> global TEST_CASES

Why?

> class Test090Case1:

> TEST_CASES['Test090Case1'] = Test090Case1

> def Main():
>     th = TestHarness()
>     for tc in TEST_CASES.keys():
>         th.setUp(tc)

Note that tc is a string. 
Did you mean th.setup(TEST_CASES[tc]) or 
for tc in TEST_CASES.values():?

> What am I doing wrong here?

It started with class versus instance object confusion. 
I don't know if you meant to use instance methods or 
class methods. Study class methods: @classmethod decorator 
and self versus cls. Don't stop at one bug. 
Bring them to the dojo. 

https://pypi.python.org/pypi/pytest
http://www.python.org/dev/peps/pep-0008/
https://en.wikipedia.org/wiki/The_Elements_of_Programming_Style
http://web.archive.org/web/20090627155454/www.greenend.org.uk/rjk/2000/06/14/quoting.html
https://en.wikipedia.org/wiki/The_Practice_of_Programming
cohpy.org



More information about the CentralOH mailing list