What the agent does
Python 3.12 deleted a set of unittest.TestCase method names that had been deprecated aliases for over a decade: assertEquals, assertNotEquals, assertAlmostEquals, assert_, assertRegexpMatches, assertRaisesRegexp and the failUnless family among them. A suite that used them does not fail to import. Each test runs until it reaches the first old name and then errors, so the report looks like a wave of broken tests when the code under test has not changed. atbrask/CMS50Dplus, a small library that reads a pulse oximeter over a serial port, is a clean example. Its tests live in one file, unittests.py, with 16 test methods and 31 calls to assertEquals.
The agent runs the file directly, python unittests.py, as its unittest.main() block intends, on two interpreters, after installing the two packages setup.py names, python-dateutil and pyserial. On Python 3.11 all 16 pass and the run prints DeprecationWarning: Please use assertEqual instead. On Python 3.12 the same file reports FAILED (errors=12), each error ending in the title's message with the hint Did you mean: 'assertEqual'?. The four tests that survive are the ones that only call assertRaises. That split matters for the report: twelve errors, one cause, none of them an assertion that compared two values and found them different.
It then renames by a fixed table, old alias to current name, and only on method calls whose receiver is a test case. A blanket text replacement is tempting and wrong at the edges: a project may define its own helper called assert_, or mention an old name inside a string a test checks. The agent searches for every removed alias, including ones this file does not use, and confirms afterwards that none is left. For a larger suite it uses a tool built for the job, such as pyupgrade or ruff's rule for deprecated unittest aliases, and reviews the diff the tool produces.
With the 31 calls renamed, the file runs 16 tests and passes on Python 3.12 and on 3.13, and still passes on 3.11 with the warning gone. Turning warnings on for the 3.12 run shows what is next in line: datetime.datetime.utcnow() is deprecated, called once in cms50dplus/cms50dplus.py and in every test method. The agent leaves that alone, because it is a change to library code with its own questions, and lists it in the pull request as the next deprecation to schedule.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "The tests in this project fail on Python 3.12 or later with AttributeError: '...' object has no attribute 'assertEquals' (or another removed unittest alias). Fix the tests. Run the suite the way the project runs it (its CI config, tox.ini, Makefile or README says how) on the newest Python available and, if you can install it, on the newest Python that still has the aliases, and report the counts for each. Search the whole repository for every alias Python 3.12 removed from unittest.TestCase: assertEquals, assertNotEquals, assert_, assertAlmostEquals, assertNotAlmostEquals, assertRegexpMatches, assertNotRegexpMatches, assertRaisesRegexp, assertItemsEqual, assertDictContainsSubset, and the failUnless, failIf and failUnlessEqual family. Rename each call to its current name. Only change calls on test case objects; leave strings, comments about history, and unrelated functions with similar names alone. assertDictContainsSubset has no direct replacement: rewrite those assertions explicitly and show each one. Do not change the code under test, and do not change what any assertion checks. After the rename, run the suite again on every Python version the project declares that you can install, and report results. If tests still fail, show that the failure is unrelated to the rename and list it without fixing it. Run the suite once more with warnings enabled and list other deprecation warnings as follow-ups. Open a pull request.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- 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.
- 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.
- 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 whose diff is confined to test files. For CMS50Dplus that is 31 changed lines in unittests.py, each one a method name. The description gives the before and after counts per interpreter in a small table: 16 passing with a warning on the older Python, 12 errors on the newer one before the change, 16 passing on both after it. It states which aliases were searched for and found, and which were searched for and absent.
Below that is the list of what the agent sees and does not touch. Here it is the utcnow deprecation with the file and line in the library where it originates. In other projects this section tends to hold the real news: a test that fails on the new Python for a reason of its own, which the wave of alias errors had been hiding.
Review is quick by design. A reviewer confirms that no line outside the tests changed and that no assertion was weakened, which a rename cannot do, and merges. The follow-up list becomes issues.
Run it on every test job that fails on Python 3.12
The error shows up when a CI matrix gains a new Python or a base image moves. Have the failing job report itself: add a final step to the test workflow that runs only on failure, checks the log for has no attribute 'assert or has no attribute 'fail, and if it matches posts the failing output to the URL of a webhook trigger on an automation that holds the prompt above. The step sends Authorization: Bearer with the trigger's secret, stored as a repository secret. The posted body, up to 64 KB, is placed after the saved prompt as event text.
A matrix build fails once per job, so several posts can arrive for one commit. The automation's max runs per hour limits how many runs that starts; set it to one or two for this prompt, since a single run fixes the whole suite. For libraries with no CI at all, like the example, a scheduled run that tries the newest Python once a month finds the problem before a user does.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The rename is trivial and the verification is the work: two or three interpreters, a clean environment for each, and the suite run before and after on all of them. That is tedious on a laptop that has one Python installed. The agent sets the interpreters up in its own sandbox, and the counts in the pull request come from commands whose output is kept in the session, so the claim that nothing else broke is one a reviewer can check.
It also separates one cause from the noise around it. Twelve red tests look like twelve problems, and a hurried fix under that impression often goes too far, pinning Python back or deleting tests. A run that reports twelve errors with one cause, fixes that cause, and then shows what remains gives the team an accurate picture of where the code stands on the new interpreter.
Frequently asked questions
Which unittest methods did Python 3.12 remove?
The deprecated aliases: assertEquals, assertNotEquals, assert_, assertAlmostEquals, assertNotAlmostEquals, assertRegexpMatches, assertNotRegexpMatches, assertRaisesRegexp, and the old failUnless, failIf and failUnlessEqual style names. The current names, such as assertEqual, assertTrue and assertRegex, have existed for many releases, so renaming does not raise your minimum Python.
Does this happen under pytest too?
Yes. pytest runs unittest.TestCase classes with the standard library's own assertion methods, so a removed alias raises the same AttributeError there. Tests written as plain functions with assert statements are unaffected.
Why did the tests pass yesterday?
The Python version under them changed: a CI image, a python-version entry, or a rebuilt virtual environment moved to 3.12 or later. On earlier versions the aliases worked and printed a DeprecationWarning, which is easy to overlook in a run that passes.
Can I use a tool instead of an agent for the rename?
For the rename itself, yes: pyupgrade and ruff both rewrite the aliases. What they do not do is install several interpreters, run your suite on each, tell the alias errors apart from other failures, and write up what is left. If the rename is all you need, run the tool.
What replaces assertItemsEqual and assertDictContainsSubset?
assertItemsEqual was the Python 2 name and became assertCountEqual. assertDictContainsSubset has no successor; the agent rewrites each use as an explicit comparison of the relevant keys and shows every such change, since those are the only edits here that are more than a new name.
More unittest jobs
More jobs like this: Fix a bug from an alert
- Fix "TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"" in ts-node (ts-node)
- Fix "deprecated version of actions/upload-artifact: v3" Workflow Failures (GitHub Actions)
- Fix `undefined method 'escape' for module URI` (NoMethodError) on Ruby 3 (URI)
- Fix "[DEP0169] DeprecationWarning: url.parse() behavior is not standardized" (Node.js)