# Fix "PytestDeprecationWarning: The configuration option asyncio_default_fixture_loop_scope is unset"

Yes. An agent sets the fixture loop scope in the project's pytest configuration, checks the choice against its async fixtures, and shows the suite clean.

[Run this on Rush](https://cloud.getrush.ai/run/fix-asyncio-default-fixture-loop-scope-unset-warning/pytest-asyncio/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the test set-up before the tests, because this warning is about configuration that does not exist yet. In OCCASS/aiogram_tests, a library for testing aiogram bots, `requirements.txt` and `dev_requirements.txt` list `aiogram==3.0.0b7`, `pytest` and `pytest-asyncio`, the `Pipfile` has both test packages at `*`, `tox.ini` changes into `tests` and runs `pytest`, and `pyproject.toml` has no `[tool.pytest.ini_options]` table. The tests under `tests/` and `examples/` mark coroutines with `@pytest.mark.asyncio`. A clean install resolves pytest 9.2.0 and pytest-asyncio 1.4.1.post1, and `pytest -q` prints the warning in the title from `pytest_asyncio/plugin.py` line 300 before the first dot, then passes all twenty tests.

Then it finds when the warning began and what it asks for. Installed in turn, pytest-asyncio 0.24.0 already prints it, from line 208 of its plugin, on pytest 8.3.5, and so does 1.0.0; on pytest 9.2.0 the sandbox saw it with 1.3.0 and 1.4.1 and not with 1.1.0 or 1.2.0. The text says what to do: the event loop scope for asynchronous fixtures defaults to the fixture's own caching scope, a future release will default it to `function`, and the valid values are `function`, `class`, `module`, `package` and `session`.

The choice matters only where a fixture is async. The agent lists every `async def` fixture in the project and what shares its loop: a fixture that opens a connection reused across a module needs `module` or wider, while a fixture that builds a fresh object per test is happy with `function`. This project's tests build a `MockedBot` inside each test and have no async fixtures, so `function`, the value the plugin will adopt, changes nothing. The agent writes `asyncio_default_fixture_loop_scope = "function"` under `[tool.pytest.ini_options]` in `pyproject.toml`, which pytest finds from the repository root and from the `tests` directory that tox changes into.

Proof is the same run twice. On the branch `pytest -q` prints no line containing `asyncio_default_fixture_loop_scope` and the same twenty tests pass. The agent reports the warnings that remain and why they are out of scope: a `PytestCollectionWarning` on `tests/bot.py` line 13, where a `TestCallbackData` class has an `__init__`, and two `RuntimeWarning` lines from aiogram's dispatcher about an unknown update type, both products of the `3.0.0b7` pin rather than of pytest.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "This test suite prints \"PytestDeprecationWarning: The configuration option asyncio_default_fixture_loop_scope is unset\". Read the dependency and pytest configuration files, say which pytest and pytest-asyncio a clean install resolves, and find by installing them the first pytest-asyncio release that prints the warning. List every async fixture in the project with its scope and what it holds, and from that choose the loop scope that keeps each fixture's current behaviour, preferring function where no fixture needs wider. Set asyncio_default_fixture_loop_scope to that value in the configuration file pytest already reads for this project, and check pytest finds it from every directory the tooling runs tests from. Run the suite before and after, show the warning gone and the same tests passing, and list the warnings that remain with their cause. Open a pull request with the version findings and both runs.",
  "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 adds two lines to `pyproject.toml` and nothing else. The description names the pytest and pytest-asyncio releases a clean install resolved, the first pytest-asyncio release that printed the warning, the async fixtures found and the scope chosen for them, and quotes the suite's summary line before and after. The warnings that remain are listed with their file and line and the reason each is unrelated.

A reviewer checks the fixture list against their own knowledge of the suite: a shared connection or a long-lived client in an async fixture is the case where `function` would be wrong, and the pull request's table shows whether any exists. If tests are also run from a tox or CI working directory, the reviewer confirms the configuration file sits above it.

The twenty tests here passed before and after, so the pull request claims no fix beyond the warning; it says so.

## Run it on every CI run that prints a deprecation

A deprecation is quiet until the release that turns it into a failure, so the time to act is when it first appears in a log. A CI job can grep its own pytest output for `PytestDeprecationWarning` and, on a match, post the lines to a Rush `webhook` trigger's URL with the trigger's secret in `Authorization: Bearer`; the automation's prompt tells the agent which warning text to act on.

For many repositories, a scheduled run a week that installs each one's test dependencies fresh, runs the suite and opens a pull request only where this warning appears keeps the fix ahead of the pytest-asyncio release that changes the default.

## Why run it on Rush?

The two-line fix is easy; choosing the value is the work, and it needs every async fixture read, not just the warning. The agent reads them in its sandbox, runs the suite on the resolved releases, and puts the fixture table and both runs in the pull request, so the reviewer sees why `function` is safe here rather than a config line with no argument.

Finding when the warning started means installing older pytest-asyncio releases, which nobody wants in a working environment. The sandbox is disposable, so the agent installs five of them, records which print the warning on which pytest, and reports exactly that.

## Frequently asked questions

### Which value should I set?

`function` unless an async fixture needs a wider scope to keep its loop between tests. A fixture that opens a connection shared by a module needs `module` or `session`; a fixture that builds a fresh object per test is fine with `function`. The agent lists each async fixture and its scope so the choice is visible.

### Where does the setting go?

In whichever file pytest already reads for the project: `[tool.pytest.ini_options]` in `pyproject.toml`, `[pytest]` in `pytest.ini` or `tox.ini`, or `[tool:pytest]` in `setup.cfg`. The agent checks that pytest finds it from the directory the tooling runs tests from.

### Is this a bug or just noise?

Noise today, a behaviour change later: pytest-asyncio says it will default the loop scope to `function` in a future release, and a suite whose async fixtures assume a wider loop will then start failing. Setting the value now pins the behaviour either way.

### Will the tests change?

Not when the chosen scope matches how the fixtures are used, which the agent checks. The pull request shows the same tests passing before and after, with only the warning gone.

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

- [Fix "TypeError: As of 3.10, the *loop* parameter was removed from Lock()" in asyncio](https://getrush.ai/run/fix-asyncio-loop-parameter-removed/asyncio/)
- [Fix "AttributeError: module 'base64' has no attribute 'encodestring'" in Python 3.9+](https://getrush.ai/run/fix-base64-encodestring-attribute-error/base64/)
- [Fix "AttributeError: 'Flask' object has no attribute 'before_first_request'" with Flask-SQLAlchemy](https://getrush.ai/run/fix-before-first-request-attribute-error/flask-sqlalchemy/)
- [Fix "TypeError: BotBase.__init__() missing 1 required keyword-only argument: 'intents'" in discord.py 2](https://getrush.ai/run/fix-bot-missing-intents-argument/discord-py/)
- [Fix a Scrapy Spider That Stopped Returning Items](https://getrush.ai/run/fix-broken-spiders/scrapy/)
- [Fix "DeprecationWarning: Buffer() is deprecated" (DEP0005) in Node.js](https://getrush.ai/run/fix-buffer-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/)
