How can tox install the modules via the requirements file?

PythonTox

Python Problem Overview


Our python project has a requirements.txt file which lists some dependent module. We used to use

pip install -r requirements.txt

to install these dependencies. We are now using tox to build up the test environment. My question is that how can we install the modules via requirements.txt directly.

Followings are our tox.ini and requirements.txt:

tox.ini:

[tox]
envlist=py27
[testenv]
deps=pytest
     boto
commands=py.test

rquirements.txt:

boto

Is any way to remove the "boto" from tox.ini and add something like

deps_files=requirements.txt

Python Solutions


Solution 1 - Python

 deps = -r{toxinidir}/tools/pip-requires
        -r{toxinidir}/tools/test-requires

Solution 2 - Python

What helped me is the following (the other solution didn't work for me):

deps=
    pytest
    -rrequirements.txt

This works at least if you add requirements.txt to MANIFEST.in and if you use a relatively new `tox (>= 1.6.1) version (see here).

Solution 3 - Python

I had already setup my dependencies as in the accepted answer above, however any new dependencies were not installed like they are when tox is run for the first time. To install new dependencies in the virtualenv I had to force tox to recreate the environment like so:

tox --recreate -e py27

[UPDATE: this issue should be fixed in tox v4]

Solution 4 - Python

You can put dependencies and test dependencies in requirements.txt and requirements.testing.txt in order to the root directory.

Put tox.ini in your root directory of your project and you can use the approach below to install dependencies.

[testenv] deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements.testing.txt

In addition to upgrade dependencies

[testenv] deps = -Ur{toxinidir}/requirements.txt -Ur{toxinidir}/requirements.testing.txt

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwaitingkuoView Question on Stackoverflow
Solution 1 - PythonDenisView Answer on Stackoverflow
Solution 2 - PythonDave HalterView Answer on Stackoverflow
Solution 3 - PythonjfunkView Answer on Stackoverflow
Solution 4 - PythonabdullahselekView Answer on Stackoverflow