[TIP] Test Parameterization with unittest

Doug Philips dgou at mac.com
Mon May 11 13:44:23 PDT 2009


On or about Monday, May 11, 2009, at 04:10PM, Michael Foord indited:
>When are make_tests prefixed methods called and by whom? (Are they 
>static method or instance methods?)

They are instance methods. They are called by "whomever is running the tests."

>One of the problems with unittest is that a test could be run by 
>TestRunner.run, TestCase.run or TestSuite.run. I understand that 
>creating test methods at class creation time may be too early for some 
>use cases, but it does support all the ways that tests can be run.

We started with the unittest and have added some additional features (filtering on keywords or test duration, additional test status values (SKIP, INCONCLUSIVE), etc.) and in the process we've refactored unittest a bit. So we have only one place from which tests are invoked. :)
In our use case, we determine sets of parameters to be tested (usually in combination), and so creating TestCase objects (we call them Scenarios, terribly original, I know. :( ) was easy. We already were creating them in our tests, we just had to jump through hoops to run them since they weren't full blown tests. Code has gotten noticably simpler.
As I said in a previous note, this is probably not the best solution, but it was the simplest one that got us what we needed.


I've had rather unpleasant experiences using metaclasses due to the inheritance issues they introduce...


    -Doug




More information about the testing-in-python mailing list