[Python-Dev] setUpClass and setUpModule in unittest

Guido van Rossum guido at python.org
Fri Feb 12 21:27:29 CET 2010


On Fri, Feb 12, 2010 at 12:20 PM,  <exarkun at twistedmatrix.com> wrote:
> The idea is that you're declaring what the tests need in order to work.
> You're not explicitly defining the order in which things are set up and torn
> down.  That is left up to another part of the library to determine.
>
> One such other part, OptimisingTestSuite, will look at *all* of your tests
> and find an order which involves the least redundant effort.

So is there a way to associate a "cost" with a resource? I may have
one resource which is simply a /tmp subdirectory (very cheap) and
another that requires starting a database service (very expensive).

> You might have something else that breaks up the test run across multiple
> processes and uses the resource declarations to run all tests requiring one
> thing in one process and all tests requiring another thing somewhere else.

I admire the approach, though I am skeptical. We have a thing to split
up tests at Google which looks at past running times for tests to make
an informed opinion. Have you thought of that?

> You might have still something else that wants to completely randomize the
> order of tests, and sets up all the resources at the beginning and tears
> them down at the end.  Or you might need to be more memory/whatever
> conscious than that, and do each set up and tear down around each test.

How does your code know the constraints?

> The really nice thing here is that you're not constrained in how you group
> your tests into classes and modules by what resources you want to use in
> them.  You're free to group them by what they're logically testing, or in
> whatever other way you wish.

I guess this requires some trust in the system. :-)

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list