74

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
waitingkuo
  • 89,478
  • 28
  • 112
  • 118

4 Answers4

75
 deps = -r{toxinidir}/tools/pip-requires
        -r{toxinidir}/tools/test-requires
Denis
  • 7,127
  • 8
  • 37
  • 58
  • 7
    This has the issue that it will not auto update the virtualenv – Thomas Grainger Aug 09 '13 at 14:14
  • 1
    @hangtwenty broken link. Updated link: https://caremad.io/2013/07/setup-vs-requirement/ – Jeffrey Godwyll Oct 29 '15 at 19:44
  • This gives me the error "IOError: [Errno 2] No such file or directory: '/tmp/pip-eV81Ia-build/pip-requires'". The requirements files are not automatically copied by tox into its tmp build directory. – Cerin Oct 30 '15 at 16:01
  • 7
    It might be worth mentioning you should have a `MANIFESTS.in` file that has the line `include requirements.txt`. This will ensure that our requirements file gets added to your distributed package. More information [here](https://wiki.python.org/moin/Distutils/Tutorial) @Cerin I think this will resolve your problem. – adambullmer Dec 16 '15 at 18:52
36

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).

jgosmann
  • 750
  • 9
  • 19
Dave Halter
  • 15,556
  • 13
  • 76
  • 103
  • 1
    Great help, thanks. Inclusion into `MANIFEST.in` is not required for simple call `$ tox`, but if you are using `$ devpi test`, inclusion is crucial. – Jan Vlcinsky Jul 22 '14 at 13:21
  • 13
    Note, that **There shall be no space between `-r` and `requirements.txt`**. For me, a space prevented `requirements.txt` to install. – Jan Vlcinsky Jul 22 '14 at 13:22
30

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]

jfunk
  • 7,176
  • 4
  • 37
  • 38
14

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{tox_ini_dir}/requirements.txt -r{tox_ini_dir}/requirements.testing.txt

In addition to upgrade dependencies

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

Noumenon
  • 5,099
  • 4
  • 53
  • 73
abdullahselek
  • 7,893
  • 3
  • 50
  • 40