Python 指定安装分发/设置工具包的“tests_require”依赖项的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4734292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 17:15:32  来源:igfitidea点击:

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

pythontestingsetuptoolsdistribute

提问by Danny Navarro

When I run python setup.py testthe dependencies listed in tests_requirein setup.py are downloaded to the current directory. When I run python setup.py install, the dependencies listed in requiresare instead installed to site-packages.

当我运行setup.py 中python setup.py test列出的依赖项时tests_require,会下载到当前目录。当我运行时python setup.py install,中列出的依赖项被requires安装到site-packages.

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

我如何才能将这些tests_require依赖项安装在site-packages.

采纳答案by Jason R. Coombs

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:

您不能指定测试需求的安装位置。tests_require 参数的重点是指定安装包不需要但仅用于运行测试的依赖项(您可以想象许多消费者可能想要安装包但不运行测试)。如果您希望在安装过程中包含测试要求,我会将它们包含在 install_requires 参数中。例如:

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.

据我所知,在不更改安装脚本的情况下,您无法传递任何参数来强制执行此行为。

回答by schettino72

I am using pipto achieve something like that. Instead of adding tests_requiresor extrasto my setup.py I have created a pip requirements file.

我正在使用pip来实现类似的目标。我没有在 setup.py中添加tests_requiresextras,而是创建了一个pip 需求文件

Example my dev_requirements.txtfile:

例如我的dev_requirements.txt文件:

pytest
webtest

Then to install it run:

然后安装它运行:

$ pip install -r dev_requirements.txt

回答by Tiberiu Ichim

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:

您可以使用 virtualenv 来避免这种情况,并将额外的包安装到它们的默认位置,在 lib/pythonX/site-packages 中。首先,您应该在 setup.py 中将您的测试需求定义为 extras:

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