What the agent does
Old pytest exposed the active configuration as a module global, pytest.config, so any file could call pytest.config.getoption(...). The 4.x releases deprecated it with PytestDeprecationWarning: the pytest.config global is deprecated. Please use request.config or pytest_configure (if you're a pytest plugin) instead. pytest 5.0 turned that warning into an error, and current releases have no such attribute, so the code fails with the AttributeError in the title. The right replacement depends on when the line runs. Inside a fixture or test, the configuration is request.config. At import time, such as in a skipif decorator or a module-level constant, no request exists yet and the value has to be captured in a pytest_configure hook or read through a fixture instead. The agent sorts every use into one of those two groups first.
GustavePate/lycheesync is the simple group, with complications around it. Its root conftest.py registers a --confpath option in pytest_addoption, with action="append" and default=[], and a session-scoped fixture confborg(request) reads it back through pytest.config.getoption('confpath') five times. The fixture already receives request, so each call becomes request.config.getoption('confpath') and the error is gone. tests/test_main.py pulls the fixture in with @pytest.mark.usefixtures("confborg"), which keeps working unchanged.
The complications are what make it an upgrade and not a one-line fix. requirements.txt pins pytest==2.7.3 beside pytest-cov==2.2.0 and pytest-pep8==1.0.6, and .travis.yml tests Python 2.7, 3.4 and 3.5 against a MySQL service. The Makefile runs py.test -c ./ressources/pytest.ini --cov=lycheesync --pep8 --showlocals --duration=3 -v -s --confpath=${PWD}/ressources/test_conf.json. Anyone who hits this error has already installed a newer pytest than the pin, so the agent raises the pins together and runs that exact command to see what else the new version rejects. The --pep8 flag comes from the pinned pytest-pep8 plugin, and the agent reports whether that plugin still loads; if not, it removes the flag and names a linter step as the replacement, without adding one unasked.
It also reads the fixture it is editing, because the option handling has faults the old pytest never surfaced. The check is not None is always true when the default is an empty list. With no --confpath on the command line, conf_path stays [] and os.path.exists([]) raises TypeError. With a path that does not exist, the function reaches return res with res never assigned. Each ends the session with an error unrelated to the real problem, a missing configuration file. The agent fixes these in a second commit: one getoption call, a clear pytest.UsageError when the option is absent or the file is missing, and no change to what a correct invocation does. Since the suite needs a MySQL database, the agent says whether it could start one in its sandbox and which tests it ran.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This project's tests fail with \"AttributeError: module 'pytest' has no attribute 'config'\" on a current pytest. Find every use of the pytest.config global in conftest files, tests and plugins. Sort each use into one of two groups: code that runs inside a fixture, test or hook that can receive request or config (replace with request.config or the hook's config argument), and code that runs at import time, such as skipif or parametrize decorators and module-level constants (replace by capturing the value in pytest_configure, by a fixture that calls pytest.skip, or by a marker handled in pytest_collection_modifyitems). Do not paper over import-time uses by importing private pytest internals. Then read the test dependencies: list the pinned versions of pytest and each pytest plugin, raise them together to current releases, and run the project's documented test command exactly as written in the Makefile, tox.ini or CI file. Report every further failure the new pytest causes, such as removed command-line flags, abbreviated options, unmaintained plugins, yield_fixture, or unregistered markers, and fix those that are mechanical. While editing each fixture, read it fully and report latent faults in how it handles the option, such as a default that makes a None check always true or a variable used before assignment, and fix them in a separate commit with a clear usage error. If the suite needs a service such as a database, start one in the sandbox if you can and say exactly which tests ran and which did not. Open a pull request with the commands and their output.",
"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 with separate commits for the three kinds of change: the pytest.config replacements, the dependency pins and command-line flags, and the fixture faults. The description lists each use of the global with its group and the replacement chosen. It quotes the documented test command, the first failure it produced under the new pytest, and each further failure in the order they appeared, so a reader can see that the title's error was the first of several.
A reviewer checks the import-time group most carefully, when there is one. Moving a skipif condition into a hook or fixture changes when the decision is made, and a test that used to be skipped at collection may now be reported differently. For lycheesync there are no import-time uses, so the review is mostly about the pins: which plugin versions were chosen, whether dropping --pep8 is acceptable, and which Python versions the project now tests. The description also states plainly which tests ran. If the database-backed tests could not run in the sandbox, it says so, and the reviewer runs them before merging.
Run it on every pull request labelled agent
The error usually first appears on a pull request that raises the pytest pin. Add an automation on the Project with a github trigger on pull_request.labeled, set its labels to the one your team uses to hand work to the agent, and save the prompt above. When a collaborator adds that label to the failing pull request, a run starts with the event after the prompt, so the agent knows which branch to work on. Only an owner, member or collaborator fires the trigger. A label added by a bot does not.
The same automation covers every later upgrade that breaks the suite, since the prompt asks for all failures the new version causes and not only this one. Its max runs per hour limits how many start if someone labels several pull requests at once; an event past the limit waits until the hour has room.
The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.
Why run it on Rush?
A test-runner upgrade fails in layers, and each layer only shows after the one above is fixed: the removed global, then a rejected flag, then a plugin that no longer imports. Working through them needs a clean environment per attempt, because a developer's virtual environment tends to hold a mix of old and new plugins that produces failures of its own. The agent installs from the repository's pins in its sandbox, raises them, and reruns the documented command after each change. Every command and its output is kept in the session, in order, which is the record the pull request quotes.
It can also bring up what the suite depends on. Tests that need a database are the ones people skip when checking an upgrade locally, and a pull request that says the tests pass without them is worth little. The run either starts the service and runs them, or states that it did not, and both are more useful to a reviewer than an unqualified green.
Frequently asked questions
What replaces pytest.config.getoption()?
In a fixture, request.config.getoption(name). In a hook, the config argument, or item.config and session.config where those are passed. There is also a built-in pytestconfig fixture that returns the same object, which is convenient in a test that needs one option.
How do I use a command-line option in a skipif decorator now?
You cannot read it at import time. Register a marker, then in pytest_collection_modifyitems(config, items) add pytest.mark.skip to items carrying it when the option is not set. For a single test, a fixture that calls pytest.skip() based on request.config.getoption is shorter.
Can I just pin pytest below 5?
Only on an interpreter those releases still support, and you would be pinning every pytest plugin to matching old versions as well. It delays the work and makes it larger. The replacement for this global has been available since long before it was removed, so the code can be fixed first and the pin raised after.
Will the agent rewrite my fixtures?
It changes the lines that read the global and nothing else in the first commit. Faults it finds while reading a fixture, such as a variable used before assignment, go in a separate commit that you can drop without losing the fix.