[TIP] Guidelines for where to put tests & how to package them

Michael Foord fuzzyman at voidspace.org.uk
Fri Feb 26 13:53:41 PST 2010


On 25/02/2010 05:01, C. Titus Brown wrote:
> Hi all,
>
> here at PyCon there have been a lot of packaging discussions, so I thought
> I'd spend a bit of time outlining some suggestions for where to put
> tests and how to run them.  It's been a bit of a thorn in the side of
> (among other things) continuous integration systems that there's no
> standard way to run Python tests... so let's fix that!
>
> I've produced a simple draft proposal&  example where you put your unit tests
> under a package dir, somepackage/tests/.
>
> You can run these tests with
>
>    % python -m somepackage.tests.run
>
> and you can also do (if setuptools/distribute is installed)
>
>    % python setup.py test
>    

If you're happy to depend on distutils2 and unittest2 then very soon 
there will be a standard "setup.py test" command that will continue to 
work with future versions of Python. It will probably default to 
unittest test discovery but allow you to provide a specific 'tests' 
argument (either a module or suite) and a 'testrunner' (test_runner ?) 
argument to specify a non-unittest runner if needed (testrunner defaults 
to unittest.TextTestRunner, well actually unittest2.TextTestRunner).

This means that no *specific* layout for tests need to be mandated, so 
long as it is compatible with test discovery or you do the test 
collection yourself with the 'tests' argument.

With this in place (which it isn't yet) it is unlikely that unittest / 
distutils will adopt an official 'recommended' test layout, but don't 
let that stop you... ;-)

FWIW I would rather see ponybuild use distutils2 / unittest2 (i.e. the 
recommended [1] community tools), but I understand your reluctance to 
take a dependency on anything other than a single script on the client 
side. A bootstrap script for installing dependencies would be one way 
round this.

All the best,

Michael Foord

[1] Recommended by me...

> ---
>
> Full source at http://github.com/ctb/SomePackage or downloadable
> at
>
>     http://lyorn.idyll.org/~t/transfer/SomePackage.tar.gz
>
> Comments?  Thoughts?  Complaints?  Issues I missed?
>
> thanks,
> --titus
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.





More information about the testing-in-python mailing list