What this thread does
The problem
After updating Python or test dependencies, a worker fails at startup, an import raises a typing error, or tests cannot find a fixture. Match the message and failing frame.
FastAPI tests: Task attached to a different loop
The error RuntimeError: Task attached to a different loop is addressed by FastAPI's async-test guide: create loop-dependent objects inside async functions. Check clients or database engines created at import time; move their initialization into the async lifecycle that uses them.
A fixture’s loop_scope must be at least its caching scope; tests using loop-bound resources must run on the same actual loop as those resources. See the fixture reference and test-loop concepts.
Untested experiment: combine those rules with FastAPI's HTTPX example: create httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://test") inside an async @pytest_asyncio.fixture, use async with and yield, and give fixture and consuming @pytest.mark.asyncio tests matching loop_scope="function". For shared clients, align both to the same shared loop. FastAPI's example uses AnyIO; this fixture adaptation uses pytest-asyncio. AsyncClient does not trigger app lifespan; use the guide's LifespanManager when needed.
Compatibility boundaries, checked 2026-10-20
| Component | Official boundary | Repair direction |
|---|---|---|
| Python | 3.14 event-loop docs make get_event_loop raise with no current loop | Explicit startup ownership; get_running_loop inside async code |
| Pydantic | Changelog lists 1.10.16 on 2024-06-11 and 2.7.4 on 2024-06-12 | Historical fix floors for this Python 3.12.4 signature error, not pins for every newer Python |
| pytest-asyncio | 1.0.0 changelog, 2025-05-26 removes event_loop | Migrate fixture requests and loop scopes |
Historical fix floors do not establish later-interpreter support.
No current event loop
Exact message RuntimeError: There is no current event loop in thread 'MainThread'.
Python 3.14 makes get_event_loop without a current loop an error. Other versions can fail after teardown; inspect the caller.
python --version
python -m pip show arq
For an application-owned entry point, put async initialization inside main and let asyncio.run own the lifecycle. In a file named app.py:
import asyncio
async def main():
print(asyncio.get_running_loop().is_running())
if __name__ == "__main__":
asyncio.run(main())
Run python app.py, then adapt the real startup. Inside a running coroutine use get_running_loop. A synchronous framework that intentionally drives its own loop may use new_event_loop and set_event_loop, with shutdown and close handled by that owner. Do not create an unused loop and expect tasks to run, or nest asyncio.run in a running loop. Sources checked 2026-10-20, Python event-loop API and runner lifecycle.
For arq construction failures, arq v0.28.0, released 2026-04-16, includes PR #522’s Python 3.14 event-loop fix; check framework constraints before upgrading. Do not edit installed library files.
ForwardRef recursive_guard
Exact message TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard'.
An old caller passes recursive_guard positionally to a private typing API. vfazio's merged Pydantic fix explains the Python 3.12.4 signature change. Determine whether the traceback uses standalone Pydantic or its bundled pydantic.v1 namespace.
python --version
python -m pip show pydantic
For the historical Python 3.12.4 case, choose the applicable branch below, respecting the framework's constraints. Resolve and lock a compatible release within the existing major.
python -m pip install 'pydantic>=1.10.16,<2'
For a project already using Pydantic 2, including its v1 namespace:
python -m pip install 'pydantic>=2.7.4,<3'
Run python -m pip check, then the original failing import or model test. For newer Python, verify current framework/Pydantic support first. Do not monkey-patch typing.ForwardRef, edit site-packages, switch majors just to silence this, or assume typing_extensions repairs this caller. Sources checked 2026-10-20, official changelog and maintainer-merged correction.
Removed event_loop fixture
Exact message fixture 'event_loop' not found.
pytest-asyncio removed this fixture in 1.0.0. Confirm plugin presence/loading too; an absent plugin can produce a similar missing-fixture report.
python -m pip show pytest-asyncio
python -m pytest --trace-config --collect-only
Remove event_loop parameters from async tests and fixtures; obtain the object with asyncio.get_running_loop if needed. Convert synchronous tests requesting it to async tests. Use pytest_asyncio.fixture for async fixtures in strict mode. Minimal migrated test_loop.py:
import asyncio
import pytest
@pytest.mark.asyncio
async def test_running_loop():
assert asyncio.get_running_loop().is_running()
Run python -m pytest -q test_loop.py, then the originally failing test. For a client fixture shared across tests, align fixture and consuming-test loop_scope; the loop must outlive the fixture. Follow the migration guide to remove custom event_loop implementations. Do not blindly restore a session-wide fixture or call asyncio.run inside plugin-managed async tests. Sources checked 2026-10-20, official removal and migration steps.
Recommendation by constraint
| Failing frame | Investigate first |
|---|---|
| Synchronous worker construction | Framework startup and supported Python |
| Pydantic typing helper during import | Compatible dependency update within the existing major |
| pytest fixture resolution | Plugin loading, removed requests and scope migration |
Community evidence
- arq #512: contains the constructor traceback and points to the Python 3.14 fix released in v0.28.0.
- Pydantic #9607: recursive_guard reproduction linked to the merged correction.
- OpenSearch #949: four missing-fixture test failures, not a frequency estimate. Checked 2026-10-20.
A prompt to give your agent
Read the linked official source and migration instructions before editing; do not guess from the error name. Record Python and installed dependency versions, reproduce the exact traceback, and identify whether the application, framework or pytest owns the loop. Check whether Pydantic calls originate in its v1 namespace. Propose the smallest supported change, run the original import/startup/test and report unverified compatibility claims.
Mistakes to check
Respect supported majors; avoid import-time loop ownership and mismatched fixture/test loops.
Limits
arq v0.28.0 includes the Python 3.14 construction fix; compatibility with other framework combinations requires separate verification.
Started from a post by @mbrisx, packaged by the editor. Original post