[TIP] Test functions with unittest2, reprise: philosophy

Victoria G. Laidler laidler at stsci.edu
Fri Mar 5 08:27:40 PST 2010


Hi Michael,

Yesterday you sent an example of how to use test functions with 
unittest2, and also stated that you don't plan to make this capability 
natively available. I'd like to understand your reasoning, and explain 
why I think it should be.

Unittest is the de facto standard of how to do testing in python, 
because it's in the stdlib. One of the great strengths of python, IMHO, 
is that it allows people to write either OO or procedural code, so 
developers can use the approach that best matches either the problem 
domain or their own skillset/preferences. It therefore seems to me like 
a real lack in the de facto standard to support an OO approach to 
testing, but not a function-based approach. If the code I'm testing is 
not OO, then forcing me to write my tests in an OO fashion forces me 
through an additional level of abstraction away from what I'm actually 
trying to do.

Secondly, it seems to me that as "testing evangelists", we should be 
trying to make the
entry barrier to testing as low as possible. One of the things I liked 
about unittest when I first encountered it is that I could figure out 
how to write and run tests without really understanding how it all 
worked. I couldn't make test suites, I couldn't make test runners, or 
loaders, or any of that other fancy stuff, but that was OK - I didn't 
really care how unittest worked, I just wanted to write tests for my 
software and run them, and that much I could figure out how to do as 
soon as I wrapped my brain around an object-oriented approach to testing.

The "simpletest" module that you sent around fails that level of utter 
simplicity, because it requires me to think about "loading tests", which 
I otherwise don't have to think about. I don't want to have to think 
about how unittest works when I'm writing tests: I want it to "just work". 

I also don't want to have to figure out a place for simpletest.py to 
live so it's always available whenever my tests might be run, and drop 
this extra line  at the bottom of every file that contains test 
functions. In the language of "batteries included", this is just a 
different size battery, so why isn't it included?

I look forward to hearing your reasoning about this issue.

thanks,
Vicki



More information about the testing-in-python mailing list