[TIP] use tox to test different build-time options

Antonio Cuni anto.cuni at gmail.com
Thu Oct 27 04:53:15 PDT 2016


Hi,
I have a project (capnpy[1]) which can optionally use cython to speed
things up.
[1] https://github.com/antocuni/capnpy

I would like to be possible to enable/disable cython compilation using
either a command-line switch or an env variable when running setup.py.
Moreover, my setup.py is also smart enough to always disable cython when
running on PyPy.

Since cython is optional, I would also like to automatically run my tests
in the two configurations, with and without compilation, but I could not
get tox to cooperate so far :).
Since capnpy is relatively complex, I wrote a smaller repo which showcases
the problem:
https://github.com/antocuni/toxproblem

In particular:
- setup.py decides whether to compile cython files by looking at the
USE_CYTHON env variable:
https://github.com/antocuni/toxproblem/blob/master/setup.py#L8

- there is a test to check that we actually compiled the file if the
variable is set:
https://github.com/antocuni/toxproblem/blob/master/test_foo.py#L7

- tox.ini has two envs: py27 for the normal case, and cy27 where I set
USE_CYTHON=1 to enable compilation:
https://github.com/antocuni/toxproblem/blob/master/tox.ini

Everything works well if I run things manually:

  # test without cython
  $ (rm -f foo.so; python setup.py build_ext --inplace; py.test)

  # test with cython
  $ (export USE_CYTHON=1; rm -f foo.so; python setup.py build_ext
--inplace; py.test)

However, if I use tox, it always installs the non-cython version, even in
the cy27 environment:

  $ tox
  ...
    FAIL test_foo.py::test_PYX
  ...
    py27: commands succeeded
    ERROR:   cy27: commands failed

(full output visible in the README :)).

I tried to investigate a bit, and looking at the log it seems that tox (or
maybe pip?) builds a wheel of my package, and then re-use it to install in
cy27, but then the wheel does not contain the compiled module. But I did
not manage to understand what's going on exactly.

Thank you :)
Antonio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20161027/eb52ecd7/attachment.html>


More information about the testing-in-python mailing list