Skip to content

Deprecate test command #1684

Closed
Closed

Description

@pganssle

I think there's at least some agreement in #931 that we want to remove the test command. I think we should start by raising deprecation warnings pointing people at tox, the same way we've done for the upload and register commands.

The most likely stumbling block that I see is that I think a huge number of people have created their own test command that invokes their preferred test runner, pytest or whatever. Ideally we'd want to get the deprecation warning to them as well. Hopefully most of them are using TestCommand as their base class, though if we want to get really aggressive about it we could try parsing sys.argv directly.

I think we need to warn in the following situations:

  1. If the setup.py test command is executed
  2. If tests_require is specified
  3. If aliases.test is specified in setup.cfg

It's likely that at least two of these will be specified, but I think two separate warnings would be useful.

CC: @gaborbernat @RonnyPfannschmidt @nicoddemus

Activity

  1. added
    Needs DiscussionIssues where the implementation still needs to be discussed.
    on Feb 12, 2019
  2. jaraco commented on Feb 14, 2019

    @jaraco
    Member

    The pytest-runner project does subclass the test command, and there are projects actively depending on it. I do agree we want to deprecate each, and probably both together.

  3. di commented on Feb 17, 2019

    @di
    SponsorMember

    A bit off-topic, but do we have an overarching issue for deprecating/replacing the various incantations of setup.py? If not, would probably be good to have this, as well as some documentation about migrating on https://packaging.python.org/.

    (I can create these issues if they don't already exist)

  4. jaraco commented on Mar 9, 2019

    @jaraco
    Member

    do we have an overarching issue for deprecating/replacing the various incantations of setup.py?

    Not to my knowledge.

  5. native-api commented on Jul 2, 2019

    @native-api

    I think there's at least some agreement in #931 that we want to remove the test command. I think we should start by raising deprecation warnings pointing people at tox

    Is there, really? The feeedback there is basically that tox is a large dependency and is designed for a different use case than setup.py test.

  6. jayvdb commented on Jul 3, 2019

    @jayvdb
    Contributor

    This is a great way to kill sdists. (why have sdists if they have the same contents as wheels) How quickly the lesson of sourceforge.net has been forgotten. Or more recently Oracle changing the Term of Use of the Java downloads. IMO setuptools should be moving in the opposite direction, automatically including in sdists the test modules found using test_require or identified using pytest dry-run.

    Anyways, unless setuptools also kills its plugin mechanism, someone will recreate the test command as soon as it is removed from setuptools. Maybe that is a good thing. (But if the goal is only to get that stuff out of the setuptools repo because it is hindering setuptools, why not split it off to a separate project now, rather than pretend that tox is a drop in solution)

  7. jaraco commented on Jul 3, 2019

    @jaraco
    Member

    Is there, really? The feeedback there is basically that tox is a large dependency and is designed for a different use case than setup.py test.

    Let me see if I can clarify/illustrate. There are two main concerns of setup.py test:

    • install dependencies in an environment (the current one)
    • invoke a test runner

    Tox happens to do both of these in a user-friendly, declarative way, which is what makes it a recommended replacement. The user-experience of "run tox" is comparable to "run setup.py test".

    tox does bring more sophistication (and thus friction) to the process, which is why it's somewhat not an exact match.

    Users are welcome to seek out other solutions. I wrote pip-run as one such attempt. It has a different behavior in that it always installs dependencies, so doesn't have the second-run speed improvements seen with setup.py test.

    why not split it off to a separate project now

    You're welcome to consider that. The biggest issue with setup.py test now is that it relies on easy_install and setup_requires, both of which are superseded by pip and PEP 517. Another issue is that setup.py test has no mechanism to specify the version of setuptools under which to run... dependencies need to be resolved before setup.py is invoked. Any tools that attempts to use setuptools plugins to run tests will be forever be responsible to ensure the requisite version of setuptools is installed in advance (it's too late by the time setuptools is imported).

    This is a great way to kill sdists. (why have sdists if they have the same contents as wheels) How quickly the lesson of sourceforge.net has been forgotten.

    I'm not sure I follow. Can you elaborate on what the risks are?

    IMO setuptools should be moving in the opposite direction, automatically including in sdists the test modules found using test_require or identified using pytest dry-run.

    I don't think you want to bundle any dependencies, even those for tests, for the same reasons as you don't want to bundle dependencies (you don't want to have to re-release your sdists every time a dependency updates). You want a lightweight, declarative means to declare dependencies. If bundled dependencies are valuable, a higher-level tool should build on the fundamental building blocks (independent packages) to produce and publish those bundles (similar to how Dockerhub works to host materialized environments).

  8. pganssle commented on Jul 3, 2019

    @pganssle
    MemberAuthor

    This is a great way to kill sdists. (why have sdists if they have the same contents as wheels)

    To be clear, this would change nothing about the distinction between sdists and wheels. I personally still recommend that you include your test code in your sdist, but not in the wheel. I also recommend that your tox.ini and any other test configuration should also go into the sdist.

    python setup.py test has raised an error in dateutil for a few years now, but it has not affected the content or utility of the source distributions.

  9. jayvdb commented on Jul 3, 2019

    @jayvdb
    Contributor

    To be clear, this would change nothing about the distinction between sdists and wheels.

    The reason to include tests in sdists, or even create sdists, becomes less obvious if the existing declarative syntax to describe them causes a deprecation warning. This will obviously mean packages with existing working metadata which describes their tests to sdist recipients will need to remove that metadata to be compatible with the latest setuptools. And the latest setuptools wont run the tests any more ... ? So again, why would those package maintainers bother with including tests in the sdist.

    Add to that there are members of PyPA who were already pushing projects to not include tests in sdists (because GitHub!), who will use this deprecation as additional justification for being more vocal and aggressive in their stance.

    These are not direct outcomes of this issue. However, they are fairly predictable side-effects.

    I also recommend that your tox.ini and any other test configuration should also go into the sdist.

    Great, but you are not the typical package maintainer. Unfortunately most sdists these days are not testable, usually missing test configuration or test data, until someone from a distro tries to get the sdist working, and then has to try to convince the package maintainer because the Python Packaging Guide says almost nothing about tests. Rather than trying to use @pypa resources and products to address that growing problem, it seems the developers are washing their hands of the problem, and write so many conflicting PEPs that replace each other before a significant segment of the user base has adopted the previous one usually because the implementations were all only partial completed before the authors started writing a different PEP. Compare with the Perl ecosystem, where running the tests is an automatic default part of the package installation experience, and buildbots can (and do!) run the tests of almost every package because they all use consistent metadata for finding and running the tests - packages unmodified for 10 years still build. Tox manages creating virtualenvs and running python(OS-agnostic) commands in them. It does not declaratively describe the test modules nor the test runner (I dont consider the testenv commands = to be declarative.) If setuptools isnt going to allow its metadata to describe unittest test modules, maybe pytest needs to become the recommended test runner, as its metadata in setup.cfg/pytest.ini/etc can at least hold the globs needed to know which modules are test modules and which are not.

  10. graingert commented on Jul 3, 2019

    @graingert
  11. 102 remaining items

  12. added a commit that references this issue on Sep 11, 2025
  13. added a commit that references this issue on Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions