Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ jobs:
- name: Run tests
run: uv run --no-sync pytest tests

upstream:
name: Run unit tests on anyio main
runs-on: ubuntu-latest
# The pytest plugin uses two helpers `anyio` keeps out of its public API,
# and it loads in every test run of everyone who installs `anydi`.
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: '3.12'
enable-cache: true
- name: Install dependencies
run: uv sync --all-extras --dev
- name: Take anyio from main
run: uv pip install --upgrade "anyio @ git+https://github.com/agronholm/anyio"
- name: Run tests
run: |
uv run --no-sync pytest tests
uv run --no-sync pytest tests/ext/test_pytest_plugin.py -p anydi

benchmarks:
name: Run benchmarks
runs-on: ubuntu-latest
Expand Down
14 changes: 13 additions & 1 deletion anydi/ext/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import TYPE_CHECKING, Annotated, Any, cast, get_args, get_origin

import pytest
from anyio.pytest_plugin import extract_backend_and_options, get_runner
from typing_extensions import get_annotations

from anydi import (
Expand Down Expand Up @@ -121,6 +120,19 @@ async def _resolve() -> None:
"Failed to resolve '%s' for %s", name, request.node.nodeid
)

# `anyio` keeps these out of its public API, so a version that renames them
# breaks async injection only, not every test run that imports this plugin.
try:
from anyio.pytest_plugin import extract_backend_and_options, get_runner
except ImportError: # pragma: no cover - a version that moved them
pytest.fail(
"Injecting dependencies into async tests needs " # ty: ignore[invalid-argument-type]
"`extract_backend_and_options` and `get_runner` from "
"`anyio.pytest_plugin`, which this version of `anyio` does not "
"have. Resolve the dependency in the test instead, or report it.",
pytrace=False, # ty: ignore[parameter-already-assigned]
)

anyio_backend = request.getfixturevalue("anyio_backend")
backend_name, backend_options = extract_backend_and_options(anyio_backend)

Expand Down
Loading