Small python project example with tox, pyenv and pytest.
In this repository there is an implementation of weighted indegree for directed graphs based on NetworkX, which will be tested by pytest in multiple pyenv environments.
- install python 2.7.9 and 2.7.10:
pyenv install 2.7.9
pyenv install 2.7.10
- create two new virtualenvs with names tox_example_env and tox_2-7-10:
pyenv virtualenv 2.7.9 tox_example_env
pyenv virtualenv 2.7.10 tox_2-7-10
pyenv virtualenvs
pyenv activate tox_example_env
pip install tox tox-pyenv
pyenv activate tox_2-7-10
pip install tox tox-pyenv
pyenv deactivate
- After cloning the repository set tox_example_env and tox_2-7-10 as local pyenv environments:
cd tox-example
pyenv local tox_example_env tox_2-7-10
- These python modules have to be installed in both environments:
pyenv activate tox_example_env
pip install networkx numpy pytest
pyenv activate tox_2-7-10
pip install networkx numpy pytest
pyenv deactivate
Especially pytest, otherwise py.test command will call for pytest installed in an other environment!
- Use the following tox.ini file:
[tox]
envlist = tox_example_env,tox_2-7-10
[testenv]
commands = py.test
- Then you can run tests:
By pytest : It will work only with a selected pyenv environment:
cd tox-example
pyenv activate tox_example_env
py.test
pyenv activate tox_2-7-10
py.test
pyenv deactivate
By tox : It can handle run tests for multiple pyenv environments as well
cd tox-example
tox
In this case, you will get WARNINGS because there was no deps key specified under [testenv] in the tox.ini file.
- Use the following tox.ini file:
[tox]
envlist = tox_example_env,tox_2-7-10
[testenv]
deps =
pytest
numpy
networkx
commands = py.test
- With the above file tox install all modules automatically when we run the following command:
cd tox-example
tox