开发者

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

开发者 https://www.devze.com 2023-02-05 17:18 出处:网络
When I run python setup.py test the dependencies listed in tests_require in setup.py are dow开发者_如何转开发nloaded to the current directory. When I run python setup.py install, the dependencies list

When I run python setup.py test the dependencies listed in tests_require in setup.py are dow开发者_如何转开发nloaded 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']
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.


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]"


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:

pytest
webtest

Then to install it run:

$ pip install -r dev_requirements.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消