[Python-Dev] setUpClass and setUpModule in unittest

Robert Collins robertc at robertcollins.net
Sat Feb 13 10:36:37 CET 2010


On Fri, 2010-02-12 at 12:27 -0800, Guido van Rossum wrote:
> 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).

From the pydoc:
  :ivar setUpCost: The relative cost to construct a resource of this type.
       One good approach is to set this to the number of seconds it normally
       takes to set up the resource.
  :ivar tearDownCost: The relative cost to tear down a resource of this
       type. One good approach is to set this to the number of seconds it
       normally takes to tear down the resource.
  
> > 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?

I think thats a great way to do it; in fact doing the same thing to
assign setup and teardown costs would be lovely; I should write some
glue to do that automatically for people.

-Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100213/feda1f9d/attachment-0001.pgp>


More information about the Python-Dev mailing list