[TIP] Converting a project from setup.py test to py.test

Barry Warsaw barry at python.org
Wed Jul 30 07:22:33 PDT 2014


On Jul 29, 2014, at 08:26 PM, Paul Moore wrote:

>I ought to say, by the way, that the reason I've started digging into
>tox is that I've just started using it for real, and it's absolutely
>awesome. It's made things so much easier for me, and I can't believe
>it's taken me so long to start using it. So many thanks!

Here, here!  In fact, I think there's something really deeper about tox that I
love.  Even if you don't care about testing your code with multiple versions
of Python, tox allows you to centralize and homogenize how your tests are run,
in one simple command.

For a long while I had hoped that something like `python setup.py test` would
be the standard way of running tests.  The idea being if I can grab a random
project off of PyPI and run that command, I'd have a pretty good chance (say
80-90%) of running the package's test suite.  This hasn't happened though for
lots of reasons.  And because of the pace of distutils/setuptools/packaging
development over the last *many* years, there isn't a standard metadata way of
saying "here's how to run my package's tests".

With my distro hat on, this is important for us because we really like to run
a package's own test suite when we build the package for the distro[*].  When
we want to turn these own, it takes some work to inspect the source and futz
around with things to get the tests to run.  Many distro packages don't run
tests at build time because of the wide variety in runners, and especially
environment setup.

When I see a tox.ini file though, I get happy because I know that I can add a
build-time dependency on tox, and then tweak one flag in the package artifacts
to get the tests run - against all supported versions of Python.

There can be some hiccups along the way, such as sussing out and specifying
the test dependencies (our build farm has no access to PyPI obviously).  Some
of that I don't think tox can help with, but sometimes we also have to edit
the tox.ini file to adjust things for the build environment.  It's been on my
todo list to try to tease out the details in way that I can make meaningful
suggestions or patches to tox that would help us out.  In general though, it
involves factoring out things that are environmental, such as dependencies
that would come from the system rather than PyPI, or the list of supported
Python versions to run tox against.

Anyway, all that said, tox is the bees knees and an essential part of the
development process for my own code.

Cheers,
-Barry

[*] in my case, Debian and Ubuntu, but I'm sure the Fedora/RH guys and other
distro and distro-like collections care about this too.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140730/d306e7cb/attachment.pgp>


More information about the testing-in-python mailing list