[Python-Dev] setUpClass and setUpModule in unittest

Robert Kern robert.kern at gmail.com
Fri Feb 12 00:00:51 CET 2010


On 2010-02-11 16:20 PM, Ben Finney wrote:
> Guido van Rossum<guido at python.org>  writes:

>> The argument that a unittest framework shouldn't be "abused" for
>> regression tests (or integration tests, or whatever) is also bizarre
>> to my mind. Surely if a testing framework applies to multiple kinds of
>> testing that's a good thing, not something to be frowned upon?
>
> To my mind, an API should take a stand on the “right” way to use it,
> rather than being a kitchen-sink of whatever ideas had any support.
> Doing something the right way should be easy, and doing something the
> wrong way should be awkward.

setUpClass and setUpModule are the "right" way to do many types of integration 
and functional tests. Integration and functional tests are vital tasks to 
perform, and unittest provides a good framework otherwise for implementing such 
tests.

>> There are several alternative testing frameworks available outside the
>> standard library. The provide useful competition with the stlib's
>> unittest and doctest modules, and useful inspiration for potential new
>> features. They also, by and large, evolve much faster than a stdlib
>> module ever could, and including anyone of these in the stdlib might
>> well be the death of it (just as unittest has evolved much slower
>> since it was included).
>
> Right. This is an argument in favour of being assertive and parsimonious
> in the design of the standard-library ‘unittest’ API: this is the clear
> and obvious way to use this API, and if someone wants to do it a
> different way there are alternatives available.

I would agree if the requirements for unit testing and integration/functional 
tests were so different. However, unittest provides most of the necessary 
infrastructure that is common to all of those kinds of testing. It's just that 
the latter kinds of tests also could use setUpClass/setUpModule. It would be a 
waste (and honestly kind of ridiculous) to force people to use a whole new 
framework (which would duplicate unittest in almost its entirety) for want of 
those two methods.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco



More information about the Python-Dev mailing list