Specify where to install ‘tests_require’ dependencies of a distribute/setuptools package

Each Answer to this Q is separated by one/two green lines.

When I run python setup.py test the dependencies listed in tests_require in setup.py are downloaded to the current directory. When I run python setup.py install, the dependencies listed in requires are instead installed to site-packages.

How can I have those tests_require dependencies instead installed in site-packages?

You cannot specify where the test requirements are installed. The whole point of the tests_require parameter is to specify dependencies that are not required for the installation of the package but only for running the tests (as you can imagine many consumers might want to install the package but not run the tests). If you want the test requirements to be included during installation, I would include them in the install_requires parameter. For example:

test_requirements = ['pytest>=2.1', 'dingus']
    # ...
    tests_require = test_requirements,
    install_requires = [
        # ... (your usual install requirements)
    ] + test_requirements,

As far as I know, there’s no parameter you can pass to force this behavior without changing the setup script.

You can use a virtualenv to avoid this and install the extra packages to their default locations, inside lib/pythonX/site-packages. First, you should define your testing requirements as extras, in setup.py:

    # ...
        # ... (your usual install requirements)
        'testing': [
            # ... (your test requirements)

Then install your package with test requirements like this:

pip install -e ".[testing]"

I am using pip to achieve something like that. Instead of adding tests_requires or extras to my setup.py I have created a pip requirements file.

Example my dev_requirements.txt file:


Then to install it run:

$ pip install -r dev_requirements.txt

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .