Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a package be required only for tests, not for installation?

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.

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?

like image 955
selwyth Avatar asked Feb 11 '17 18:02

selwyth


People also ask

How do I add a package to text requirements?

Install packages with pip: -r requirements.txt You can name the configuration file whatever you like, but requirements.txt is often used. Put requirements.txt in the directory where the command will be executed. If it is in another directory, specify its path like path/to/requirements.txt .

Should Python tests be in package?

Tests are put in files of the form test_*. py or *_test.py , and are usually placed in a directory called tests/ in a package's root.

What is pip install test?

The intent of this package is to provide a simple module that can be easily installed and uninstalled. This provides a straightforward mechanism for showing that an arbitrary environment is capable of installing third party modules via pip.


1 Answers

Yes, it's simple in 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]
like image 53
wim Avatar answered Sep 30 '22 03:09

wim