# RuntimeError: Event loop is closed

- **ID:** `python/pytest-asyncio-event-loop-closed`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

With pytest-asyncio, the default function-scoped event loop is torn down after the first async test, but a session-scoped async fixture or a lingering task still references the closed loop.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 0.23.x | active | — | — |
| 0.24.x | active | — | — |
| 0.25.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   # pytest.ini
[pytest]
asyncio_mode = auto
asyncio_default_fixture_loop_scope = session
   ```
2. **** (85% success)
   ```
   # conftest.py
import asyncio, pytest

@pytest.fixture(scope='session')
def event_loop():
    loop = asyncio.new_event_loop()
    yield loop
    loop.close()
   ```

## Dead Ends

- **** — pytest-asyncio already manages the loop; creating a new one mid-test orphans the fixture's loop and the error persists on teardown. (80% fail)
- **** — The marker is likely already present; the problem is loop scope mismatch, not the missing marker. (70% fail)
