[Distutils] Where should I put tests when packaging python modules?

Donald Stufft donald at stufft.io
Tue Oct 6 11:54:25 CEST 2015


On October 6, 2015 at 3:21:04 AM, Glyph Lefkowitz (glyph at twistedmatrix.com) wrote:
> > Inside the package.
>  
> If you put your tests outside your package, then you can't install  
> the tests for two packages simultaneously, because everyone's  
> tests are just in the top-level package "tests". This tends to  
> infest the whole package, since then tests import things from  
> each other using 'from tests import ...'. This is recommended  
> by the hitchhiker's guide, and seconded by . 

I dislike putting tests inside the package.

The supposed benefit is that anyone can run the tests at anytime, but I don't
find that actually true because it means (as someone else pointed out) that you
either have to depend on all your test dependencies or that there is already an
additional step to install them. If you're going to have to locate and install
the test dependencies, then you might as well fetch the tarball with tests as
well.

Someone suggested setuptools test_requires, but that only functions when you
have a setup.py available and you execute ``setup.py test``. It does not help
you at all once the package is installed and the sdist is gone.

I also don't think people actually run the tests when they are installed in any
significant number, at least I've never once in my life done it or even had a
desire to do it.

Some projects have test suites which are significantly large too. The PyCA
cryptography project for instance, has to ship it's vectors as an additional
package to reduce the size of the final build product.

-----------------
Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA




More information about the Distutils-SIG mailing list