pip install test dependencies for tox from setup.py

前端 未结 4 967
你的背包
你的背包 2020-12-16 09:57

I made my project with setuptools and I want to test it with tox. I listed dependencies in a variable and added to setup() parameter (

4条回答
  •  粉色の甜心
    2020-12-16 10:44

    Solution

    Tox 2.6 introduced extras option. This will install extras from the sdist it just built, only for that sdist and at the time it was doing the normal sdist install.

    setup.py should look like:

    setuptools.setup(
        ...
        extras_require={
            'tests': ['pytest>=3.7.0', 'more_packages'],
        },
        ...
     )
    

    tox.ini should look like:

    [testenv]
    ...
    extras = tests
    ...
    

    Concerns

    Other approaches may get similar results but introduce unnecessary risk and limits the usefulness of other features:

    deps =.[tests] is a bit of a hack. The field is for packages the environment needs. If setup.py install_requires references another package you develop, you could use it to pull in a pre-release version of it. As shown, it will install your whole package from your working directory (whatever state that is in!) just to get at the list of packages in tests. install_command will run next, installing your newly minted sdist. In short, issues with the sdist may be masked since you already have installed from your working copy.

    Editing install_command is overkill. It'll overwrite items installed via deps. (again maybe you used it to install a specific version of a package).

    tests_require is used when python setup.py test is run. Tox recommends avoiding python setup.py test so you can ignore tests_require all together.

提交回复
热议问题