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

Zak Kohler y2k at y2kbugger.com
Tue Feb 5 11:56:58 EST 2019


pytest - https://docs.pytest.org/en/latest/

the std-lib unittest is a less feature rich, but native solution.

On Tue, Feb 5, 2019 at 11:19 AM Joshua Kramer <joskra42.list at gmail.com> wrote:
>
> 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
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh


More information about the CentralOH mailing list