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

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?


Solution 1:

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']
setup(
    # ...
    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.

Solution 2:

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:

setup(
    # ...
    install_requires=[
        # ... (your usual install requirements)
    ],
    extras_require={
        'testing': [
            # ... (your test requirements)
        ]
    },
)

Then install your package with test requirements like this:

pip install -e ".[testing]"