可以只需要一个软件包来进行测试,而不需要安装吗? [英] Can a package be required only for tests, not for installation?

查看:62
本文介绍了可以只需要一个软件包来进行测试,而不需要安装吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为现有的可点子安装项目添加功能,项目所有者认为我在setup.py安装要求中添加了pandas太繁重",因为该项目应保持精简.我要添加的功能不需要pandas(因为该功能是对pandas.DataFrame对象的操作),但是我为此编写的单元测试要求将pandas转换为setUp的测试DataFrame进行更改

I'm adding functionality to an existing pip-installable project, and the project owner feels that my adding of pandas to the setup.py installation requirements is 'too heavy', as the project should remain slim. The functionality I'm adding does not require pandas (because the functionality is operations on top of a pandas.DataFrame object), but the unit tests I wrote for it require invoking pandas to setUp a test DataFrame to mutate with.

是否有某种方法仅对单元测试要求pandas?还是我只是不将其添加到需求中,并在运行该单元测试时引发错误以手动安装pandas?

Is there some way to require pandas only for the unit tests? Or do I just not add it to the requirements, and raise an error to manually install pandas when that unit test is run?

推荐答案

是的,在setuptools中很简单:

# setup.py
from setuptools import setup

setup(
    name='your_app',
    ...
    install_requires=...
    extras_require={
        'dev': [
            'pytest', 'pandas', 'coverage',  # etc
        ]
    },
)

现在,当您在应用程序上进行开发时,请使用:

Now when you develop on the app, use:

pip install --editable .[dev]

这篇关于可以只需要一个软件包来进行测试,而不需要安装吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆