[TIP] tox and coverage across multiple envs
Andrew Dalke
dalke at dalkescientific.com
Sat Sep 10 03:00:52 PDT 2011
(Was deep in a code rewrite and put off worrying about cross-env testing for a few weeks.)
On Aug 10, 2011, at 12:29 PM, Michael Foord wrote:
> On 09/08/2011 09:20, Andrew Dalke wrote:
>> [snip...]
>>
>> Also, when the tests find an error, I find that it's hard
>> to get to a reproducible state because each of my environments
>> has different environment variables. (LD_LIBRARY_PATH, path
>> to license file, etc.) Is there any way to do something like
>>
>> tox -e py26-rd201106 --run python
>>
>> and get me into that specific Python along with the right
>> environment setup? Or is there some other way to handle this?
> Perhaps:
>
> .tox/py26-rd201106/bin/python
That unfortunately doesn't set the environment variables
% .tox/py25-ob223/bin/python
Python 2.5.4 (r254:67916, Jun 24 2010, 21:47:25)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import openbabel
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named openbabel
>>>
If you look in my tox.ini you'll see I set up a number of environment variable
% fgrep -A 8 "[testenv:py25-ob223]" tox.ini
[testenv:py25-ob223]
basepython=/Users/dalke/envs/py25-ob223/bin/python2.5
setenv=
TOX_CHEMFP_TEST=py25,x32,ob223
BABEL_LIBDIR=/Users/dalke/envs/openbabel-2.2.3/lib/openbabel/2.2.3
BABEL_DATADIR=/Users/dalke/envs/openbabel-2.2.3/share/openbabel/2.2.3
DYLD_LIBRARY_PATH=/Users/dalke/envs/openbabel-2.2.3/lib
PYTHONPATH=/Users/dalke/envs/py25-ob223/lib/python2.5/site-packages/
I need to set most of them in order to run
% env \
? BABEL_LIBDIR=/Users/dalke/envs/openbabel-2.2.3/lib/openbabel/2.2.3 \
? BABEL_DATADIR=/Users/dalke/envs/openbabel-2.2.3/share/openbabel/2.2.3 \
? DYLD_LIBRARY_PATH=/Users/dalke/envs/openbabel-2.2.3/lib \
? PYTHONPATH=/Users/dalke/envs/py25-ob223/lib/python2.5/site-packages/ \
? .tox/py25-ob223/bin/python
Python 2.5.4 (r254:67916, Jun 24 2010, 21:47:25)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import openbabel
>>>
None of the packages I deal with are on PyPI, and they are layers
on top of C++ packages which are installed separately. For example,
the first three environment variables in my `env` are requirements
of the C++ code. In another case I need to point to a license file
to use a proprietary package, and I want to test if I handle the
case when the license environment variable isn't present.
I thought about having
tox -e py26-rd201106 --shell
which gives me the Python prompt for that environment, but I want
more than that. My package includes a few command-line tools. If
there's something wrong with the tests for that tool then I would
like to do
tox -e py26-rd201106 --run ob2fps --options --to --my tool
so I can debug it more effectively inside the context of that
environment.
(However, since my command-line tools are basically:
try:
from chemfp.commandline.ob2fps import main()
main()
except KeyboardInterrupt:
raise SystemExit()
then this is not critical as I could make the right call
from the Python shell, as
from chemfp.commandline.ob2fps import main()
main("ob2fps --options --to --my tool".split())
)
Andrew
dalke at dalkescientific.com
More information about the testing-in-python
mailing list