# Fix "Support for the test command was removed in Setuptools 72"

Yes. An agent moves the tests off python setup.py test, keeps the same pytest arguments and test dependencies, and updates tox and CI to call pytest directly.

[Run this on Rush](https://cloud.getrush.ai/run/fix-setup-py-test-command-removed/setuptools/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The message comes from projects that taught `setup.py` to run their tests. jeffknupp/sandman2 is the classic shape: line 4 of `setup.py` is `from setuptools.command.test import test as TestCommand`, a `PyTest` subclass sets `test_args` to `--strict`, `--verbose`, `--tb=long` and `tests`, and `setup()` receives `tests_require=['pytest', 'pytest-cov', 'pytest-flask']` and `cmdclass={'test': PyTest}`. Two files then depend on it. `tox.ini` has `commands = {envpython} setup.py test`, and `.travis.yml` runs `coverage run --source=sandman2 setup.py test`. The agent finds all three before changing anything, because fixing `setup.py` alone leaves two callers pointing at a command that no longer exists.

It then pins down which failure a given environment produces, since there are two and they need different urgency. With setuptools 71.1.0 the command still runs. With 72.0.0 the import on line 4 fails with `ModuleNotFoundError: No module named 'setuptools.command.test'`, and because that line is at the top of `setup.py`, every use of the file fails with it, installs included. From 72.1.0 onward the module is back as a stub, so the import succeeds and installs work again, and what you get is quieter: a `SetuptoolsDeprecationWarning: The test command is disabled and references to it are deprecated`, a note that `tests_require` is an unknown distribution option, and, only when someone actually runs `python setup.py test`, the `RuntimeError` in the title. The stub is still there in setuptools 84.2.1. So most projects are in the second state: they install fine and their documented test command is dead.

The fix moves each piece to where current tools read it. The pytest arguments go into configuration, an `addopts` line and `testpaths = tests`, so that plain `pytest` does what the subclass did. The agent checks one flag on the way: `--strict` was long an alias for `--strict-markers` in pytest, so it looks at what the pytest version being installed does with it and writes the explicit spelling. The three `tests_require` packages become an extra, so `pip install -e .[test]` installs them; nothing installs `tests_require` any more. The `PyTest` class, the import and the `cmdclass` entry are deleted. `tox.ini` gets `commands = pytest` with the extra, and the CI script runs `coverage run -m pytest`. The `python setup.py develop` install line in the same CI file is the same style of call, and the agent replaces it with `pip install -e .` in the same commit.

Last, it shows the tests themselves were never the problem. With the versions this repository pins and Python 3.8, `pytest --strict --verbose --tb=long tests` passes 36 tests. The agent runs the direct command before and after its edit and reports both, so the pull request is visibly a change to how tests are started and not to what they check. This project's `Makefile` already calls `py.test --cov=sandman2 tests`; the agent leaves that target as it is and notes that it was the one entry point that kept working.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Running python setup.py test in this project fails with \"RuntimeError: Support for the test command was removed in Setuptools 72\" (or, on setuptools 72.0, \"No module named 'setuptools.command.test'\"). Find every place that depends on the setup.py test command: the import and any TestCommand subclass in setup.py, cmdclass, tests_require and test_suite, and every caller in tox.ini, the Makefile, CI files and the README. Before editing, run the tests directly with pytest using the same arguments the subclass passed and save the result. Then: move those arguments into pytest configuration so that plain pytest behaves the same; turn tests_require into a test extra; delete the TestCommand import, the subclass and the cmdclass entry; change every caller to run pytest (or coverage run -m pytest where coverage was used); replace any python setup.py develop or install call in CI with pip. If a pytest flag the subclass passed is deprecated or has changed meaning in the pytest version you install, use the explicit modern flag and say so. Do not change any test or pinned runtime dependency. Run the direct pytest command again and confirm the same tests pass, and run python setup.py --version with the newest setuptools to confirm setup.py still loads without the test-command warning. Open a pull request listing each caller you changed and the two test results.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that edits `setup.py`, the pytest configuration, `tox.ini` and the CI file, and touches no test. Its description lists the callers that were found, one line each with the old command and the new one, and gives the direct pytest result before and after. For sandman2 that is the same 36 passing tests both times. It also records the setuptools version used for the final `python setup.py --version` check and that the test-command warning is gone from its output.

A reviewer looks for anything still calling the old command: a README section, a release script, a Docker build step. They confirm the test extra holds exactly the packages `tests_require` named, and that the configured pytest arguments match what the deleted class passed. If the project publishes to a package index, they also confirm `setup.py` still builds, since the edit removed a class from the file that defines the package.

## Run it on every Monday morning

This breakage arrives with a build-tool release, not with a commit of yours, so a calendar suits it better than a push. Give the Project an automation with a `schedule` trigger, a `cron` for Monday morning in your `timezone`, and a prompt that creates a fresh environment with the newest setuptools, pip and pytest, runs the project's documented install and test commands exactly as the README and CI file state them, and opens a pull request only if one of them fails or prints a deprecation notice from the packaging tools.

A quiet week produces a short answer and no pull request. A schedule fires as the member who last edited the automation, and turning the automation back on after a pause moves it to its next slot instead of replaying the Mondays it missed.

## Why run it on Rush?

The failure depends on which setuptools happens to be installed, and that differs between a laptop's long-lived virtualenv, a tox environment and a CI image. Reproducing all the cases means building clean environments at specific versions, which is tedious by hand and exactly what a throwaway sandbox is for. The agent installs 71, 72.0 and the current release side by side, runs the same command in each, and the three outputs stay in the session for the reviewer.

It also needs the whole repository searched, not one file fixed. The dead command is typically named in four or five places, and the ones outside `setup.py` only fail when somebody next runs tox or cuts a release. One run reads every caller, changes them together, and returns a single pull request with the before and after of the test command, so the fix lands complete instead of being rediscovered file by file.

## Frequently asked questions

### What replaces python setup.py test?

Calling the test runner directly: `pytest`, or `python -m unittest` for unittest suites, usually through tox or nox for multiple interpreters. The arguments that lived in a `TestCommand` subclass move to the runner's configuration, and the test dependencies move to an extra.

### Can I pin setuptools below 72 instead?

It works for a while and it has to be pinned everywhere the project is built, including isolated builds that read `pyproject.toml`. Other tools keep raising their minimum setuptools, so the pin tends to break something else later. Moving the tests off the command is a small change that does not expire.

### What happens to tests_require?

Current setuptools reports it as an unknown distribution option and installs nothing from it. The agent moves the same packages to an extra such as `test`, so `pip install -e .[test]` and tox both install them explicitly.

### Why do installs fail too on setuptools 72.0?

Because the import of `setuptools.command.test` is at the top of `setup.py`, and that release removed the module outright. Later releases restored it as a stub, which is why installs work again while the command itself raises. Deleting the import fixes both.

## More setuptools jobs

- [Fix "error in setup command: use_2to3 is invalid" in setup.py](https://getrush.ai/run/fix-setuptools-use-2to3-error/setuptools/)
- [Fix "No module named 'pkg_resources'" by Migrating to importlib.resources](https://getrush.ai/run/migrate-pkg-resources-to-importlib-resources/setuptools/)
- [Fix "SetuptoolsDeprecationWarning: License classifiers are deprecated" and "project.license as a TOML table is deprecated"](https://getrush.ai/run/fix-license-classifiers-are-deprecated/setuptools/)

## More jobs like this: Upgrade dependencies weekly

- [Fix "The sphinxcontrib.applehelp extension used by this project needs at least Sphinx v5.0"](https://getrush.ai/run/fix-sphinxcontrib-applehelp-version-error/sphinx/)
- [Fix "The Default Datetime Adapter Is Deprecated as of Python 3.12" in a sqlite3 App](https://getrush.ai/run/fix-sqlite3-default-datetime-adapter-deprecated-warning/sqlite3/)
- [Fix "'Starlette' object has no attribute 'route'" After Upgrading to Starlette 1.0](https://getrush.ai/run/fix-starlette-object-has-no-attribute-route/starlette/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
