[CentralOH] Strange Class Behavior

Joshua Kramer joskra42.list at gmail.com
Thu Feb 6 15:54:55 CET 2014


Hello Everyone,

I'm writing a testing utility.  I have an odd problem with properly
dereferencing objects within a class.  Here is my structure:

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

global TEST_CASES
TEST_CASES = {}

class Test090Case1:
    def setUp(self):
        #Do stuff to set up the test
    ..... More code below

TEST_CASES['Test090Case1'] = Test090Case1

2. A file called test_sql.py.  It has the following:

from sql_cases import TEST_CASES

class TestHarness:
    def setUp(self, test_case):
        test_case.setUp()
        ... More code below

def Main():
    th = TestHarness()
    for tc in TEST_CASES.keys():
        th.setUp(tc)
    ... More code below

When I run this, I get an error:

TypeError: unbound method setUp() must be called with Test090Case1 instance
as first argument (got nothing instead)

If I change the line in TestHarness.setUp to this:
test_case.setUp(test_case)  I get the following:

TypeError: unbound method setUp() must be called with Test090Case1 instance
as first argument (got classobj instance instead)

In this case, the classobj is an instance of a class called
sql_cases.Test090Case1.

I am not sure why a) The object Test090Case1.setUp doesn't run with its own
class in the "self" variable; and b) Why there is a difference between
sql_cases.Test090Case1 and Test090Case1.

What am I doing wrong here?

Thanks!
-JK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20140206/fccadc64/attachment.html>


More information about the CentralOH mailing list