# Fix "AttributeError: module 'unittest' has no attribute 'makeSuite'" on Python 3.13

Yes. An agent replaces makeSuite with the loader call the deprecation named, then proves the same number of tests still run on the old and new Python.

[Run this on Rush](https://cloud.getrush.ai/run/fix-unittest-makesuite-attribute-error/unittest/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Python 3.13 removed `unittest.makeSuite()`, along with `findTestCases()` and `getTestCaseNames()`. The failure is unusual because it takes the whole test run with it: no test fails, the runner cannot build its suite at all. In fengsp/plan the entry point is `test_plan.py`, which the `Makefile` and `tox.ini` both call. It runs `plan.testsuite.main()`, which hands `defaultTest='suite'` to `unittest.main`. That `suite()` function walks the package with `pkgutil.iter_modules` and calls the `suite()` of each test module, and each of those is built from `unittest.makeSuite(SomeTestCase)`: six calls across `commands.py`, `core.py`, `job.py` and `output.py`. On 3.13 the first one raises the error in the title and the process exits before a single test starts.

The agent's first step is to record what a passing run looks like, because the fix is only correct if the count is unchanged. On Python 3.12 `python test_plan.py` collects 48 tests. Run plainly, it prints no warning about what is coming. Run with `-W always`, each of the six lines prints `DeprecationWarning: unittest.makeSuite() is deprecated and will be removed in Python 3.13. Please use unittest.TestLoader.loadTestsFromTestCase() instead.` That is why the break tends to surprise people: Python hides deprecation warnings raised in imported modules unless asked, and a custom runner like this one does not ask.

The change is the one the message gives: `unittest.defaultTestLoader.loadTestsFromTestCase(SomeTestCase)` in place of each call. The agent makes it in all four files, runs `python test_plan.py` on 3.13 and on the oldest interpreter it can install, and compares the count with the 48 from before. It leaves the hand-built `suite()` functions and the custom `main()` alone. Deleting them in favour of plain discovery is a reasonable later cleanup, but it changes how the tests are found, and a pull request that fixes a removal should not also change which tests run.

While it has the suite running it reports anything the environment was hiding. This project's `CrontabTestCase` shells out to the real `crontab` command: its setup reads the current user's crontab with `crontab -l`, overwrites it with an empty one, and its teardown writes the original back. On a machine without cron installed those three tests error with the project's own message, `couldn't read crontab; please make sure you have crontab installed`, and the same happens when cron is installed but the user has no crontab yet, because `crontab -l` exits non-zero. The agent installs cron, creates an empty crontab for the sandbox user, and only then counts results, so three environment errors are not mistaken for a consequence of the Python upgrade.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "On Python 3.13 the test run fails with \"AttributeError: module 'unittest' has no attribute 'makeSuite'\". Find how the tests are started (Makefile, tox.ini, CI file, any custom runner) and every call to unittest.makeSuite, unittest.findTestCases and unittest.getTestCaseNames. First run the suite unchanged on Python 3.12 with the project's own command, once normally and once with -W always, and save the number of tests collected and the deprecation warnings. If tests fail for reasons unrelated to Python, such as a missing system program, install what is needed in the sandbox, say what you installed, and rerun before recording the baseline. Replace each makeSuite call with unittest.defaultTestLoader.loadTestsFromTestCase and the other two with their TestLoader equivalents. Do not restructure the suite, remove the custom runner or switch to another test framework. Run the same command on Python 3.13 and on the oldest Python you can install that the project still lists, and confirm the collected count equals the baseline. If any test touches real state on the machine, such as a user's crontab, say so in the pull request. Open a pull request with the counts for each interpreter, the warning text from 3.12 and anything you noticed but did not change.",
  "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 with one kind of edit, repeated wherever the removed helper was called. On plan that is six lines in four files under `plan/testsuite`. The description gives the baseline, 48 tests collected on 3.12, the warning text that 3.12 prints only under `-W always`, and the count from 3.13 and from an older interpreter after the change. It also lists what was installed in the sandbox to get a clean baseline, which for this project is cron and an empty crontab.

The reviewer's check is arithmetic: the same number of tests before and after, on every interpreter listed. A smaller number means a test case was dropped from a suite function during the edit, and the agent is told to treat that as a failure, not a detail. If the suite cannot be made to pass for an unrelated reason, the run says which tests and why instead of presenting the change as verified.

## Run it on every test job that errors before any test runs

A `github` trigger on `check_suite.failure` in the Project's automation starts one run when the checks on a commit fail. The event is added after the saved prompt as data, so write the prompt to open the failing job's log first and continue only if the traceback ends in a removed `unittest` function. Any other failure should end the run with a short note and no pull request.

Pull requests from forks and commits by bots never fire a GitHub trigger, so a dependency bot's branch will not start this by itself. If the interpreter bump comes from such a bot, start the run from a person's rebase of that branch, or call the same prompt from a `schedule` trigger that checks the default branch once a day.

## Why run it on Rush?

This suite writes to the crontab of whoever runs it. On a developer's laptop that means the tests replace real scheduled jobs for the length of the run and depend on teardown to restore them. In a sandbox that exists only for this task there is nothing to lose, the agent can install cron and create the empty crontab the tests expect, and the interpreters it needs are installed side by side without touching anyone's machine.

The proof is also easier to trust when it is recorded. The claim in the pull request is that 48 tests ran before and 48 run after, on named Python versions. The session keeps each command and its output, including the `-W always` run that shows the six warnings, so a reviewer who doubts a number can read the line it came from.

## Frequently asked questions

### What replaces unittest.makeSuite?

`unittest.defaultTestLoader.loadTestsFromTestCase(YourTestCase)`, or the same method on a `TestLoader` you create. It returns the same kind of `TestSuite`, so `suite.addTest(...)` around it does not change. `findTestCases` becomes `loadTestsFromModule` and `getTestCaseNames` becomes the loader method of the same name.

### Why was there no warning before the upgrade?

There was one, from Python 3.11 on, but Python does not show deprecation warnings raised in imported modules by default. Running the tests with `python -W always` or `-W error::DeprecationWarning` on the old interpreter shows every call that will break.

### Should we move to pytest or test discovery instead?

You can, and both find `TestCase` classes without suite functions. It is a separate change with its own risk: discovery may pick up or miss different tests. The agent fixes the removal first and keeps the count identical, then you can ask for the migration as a second run.

### Does the fix work on older Python versions?

`loadTestsFromTestCase` is long-standing loader API, and the agent runs the changed suite on the oldest interpreter it can install to confirm. The pull request states which versions were actually run.

## More unittest jobs

- [Migrate a Python Test Suite From unittest to pytest](https://getrush.ai/run/migrate-unittest-to-pytest/unittest/)
- [Fix "AttributeError: 'TestCase' object has no attribute 'assertEquals'" on Python 3.12](https://getrush.ai/run/fix-unittest-assertequals-attribute-error/unittest/)

## More jobs like this: Fix a bug from an alert

- [Fix "TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"" in ts-node](https://getrush.ai/run/fix-unknown-file-extension-ts/ts-node/)
- [Fix "deprecated version of actions/upload-artifact: v3" Workflow Failures](https://getrush.ai/run/fix-upload-artifact-v3-deprecation/github-actions/)
- [Fix `undefined method 'escape' for module URI` (NoMethodError) on Ruby 3](https://getrush.ai/run/fix-uri-escape-nomethoderror/uri/)
- [Fix "[DEP0169] DeprecationWarning: url.parse() behavior is not standardized"](https://getrush.ai/run/fix-url-parse-deprecation-warning/nodejs/)

## 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/)
