[CentralOH] Most "Pythonic" way to accomplish this?

Joshua Kramer joskra42.list at gmail.com
Tue Feb 5 11:19:13 EST 2019


Hi Everyone!

I'm working on a sort of "test" harness for a project.  Essentially,
the harness will be able to load a series of tests that will consist
of Python classes.  I'm trying to figure out the most "Pythonic" way
to accomplish this, as well as how to pass data between tests.  Is
there a better way to express the following?  Note that I am targeting
Python 2.x with this, though I want it to be compatible with both 2.x
and 3.x.  Thanks!

class myTest:
    def __init__(self):
        pass
    def runTest:
        pass

class fileTest1(myTest):
    def __init__(self):
        pass
    def runTest:
        check_for_file_1("filename1.txt")

class fileTest2(myTest):
    def __init__(self):
        pass
    def runTest:
        check_for_file_2("filename2.txt")

class testDataObject:
    dataField1 = None
    dataField2 = None

def run_tests():
    testList = []
    testList.append(fileTest1)
    testList.append(fileTest2)

    localObject = testDataObject()

    for i in testList:
        # How do I pass localObject between each of these
        # instantiations of myTest?
        i.runTest()



Thanks!
-JK


More information about the CentralOH mailing list