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

Donald Stufft donald at stufft.io
Tue Oct 6 23:41:55 CEST 2015

On October 6, 2015 at 5:20:03 PM, Barry Warsaw (barry at python.org) wrote:
> On Oct 06, 2015, at 05:54 AM, Donald Stufft wrote:
> >I dislike putting tests inside the package.
> I'm a big fan of putting the tests inside the package. I've often looked at a
> package's tests to get a better understanding of something that was unclear
> for the documentation, or didn't work the way I expected. Having the tests
> there in the installed package makes it easier to refer to. I also find that
> with tox+nose2 (my preferred one-two punch for testing), it makes it quite
> easy to find and run the full test suite or individual tests based on a regexp
> pattern. I also like the symmetry of having a docs/ directory for doctests
> and a tests/ directory for unittests.
> For complex packages with lots of subpackages, I have lots of tests/
> directories, so that the unitests are near to the code they test. This way
> the source tree gets organized for free without additional complexity in an
> outside-the-package tests tree.

I’m not sure I understand what you’re advocating here, it sounds like you want your tests at something like mycoolproject/tests so that they are importable from mycoolproject.tests… but then you talk about symmetry with docs/ and tests/ which sounds more like you have top level directories for tests/ docs/ and then mycoolproject/.

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

More information about the Distutils-SIG mailing list