mercredi 29 juin 2016

Using py.test with compiled library code


I have a python library with the following repository structure:

repobase
 |- mylibrary
 |  |- __init__.py
 |- tests
    |- test_mylibrary.py

Up to now, running the tests could simply be done by calling py.test in the repobase directory. The import mylibrary in test_mylibrary.py then used the local code in repobase/mylibrary.

Now, I've extended the library to use compiled code. Therefore the source code at repobase/mylibrary is not functional on its own. I have to do a setup.py build. This creates repobase/build/lib.linux-x86_64-2.7/mylibrary.

Is there a reasonable way to make py.test use this directory for importing mylibrary? Given these constraints:

  1. I do not want to include any sys.path / import magic in test_mylibrary.py because this may break tests in other envrionments.

  2. I don't want to give up the possibility to run py.test from repobase. Therefore modifying the PYTHONPATH does not help because . will still be first in sys.path. And thus repobase/mylibrary would be favored over repobase/build/lib.linux-x86_64-2.7/mylibrary.

If not, what's the standard way for testing python libraries, that need building?


Aucun commentaire:

Enregistrer un commentaire