Skip to content

test: keep pytest collecting under anyio >= 4.15 (BlockingPortal deprecation) - #54

Merged
rennf93 merged 1 commit into
masterfrom
fix/anyio-blockingportal-collection
Sep 11, 2026
Merged

rennf93 merged 1 commit into
masterfrom
fix/anyio-blockingportal-collection

Conversation

@rennf93

@rennf93 rennf93 commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Closes #55

Root cause

filterwarnings = ["error"] + two upstream facts collide:

  1. anyio 4.15 (admitted by the dev pin anyio<4.16 since Update anyio requirement from <4.15 to <4.16 in the dependencies group #53) deprecates anyio.abc.BlockingPortal via its new lazy-import machinery (anyio/_lazyimport.py) and emits a DeprecationWarning on first attribute access.
  2. starlette 1.6.0 (the latest release; resolved by fastapi 0.141.1) still imports that alias at module scope in testclient.py:53.

So import fastapi.testclient — done by tests/test_adapter_fastapi.py and tests/test_performance.py — raises the warning at collection time, the error filter promotes it to an exception, and pytest exits 2 before running a single test.

Since this repo ships no uv.lock (gitignored), both our own CI (uv sync --extra dev) and the guard-core ecosystem gate resolve fresh, so any environment built after anyio 4.15's release reproduces this:

Fix

One targeted filterwarnings entry ignoring exactly that message (DeprecationWarning, prefix-matched), with a comment noting the removal condition. Everything else still fails the suite — the warnings-as-errors contract from b1f62d0 stays intact.

Capping anyio<4.15 again would only re-fight dependabot and delay the same crash. starlette master already switched to anyio.from_thread.BlockingPortal, so drop this filter once a starlette release > 1.6.0 lands — the comment in pyproject.toml says so.

Verification

Gate-identical environment (fresh uv lock resolution: anyio 4.15.1, starlette 1.6.0, fastapi 0.141.1, Python 3.10.19):

  • Before: pytest tests/test_adapter_fastapi.py --collect-only → exit 2, 2 errors during collection (matches the CI traceback byte-for-byte).
  • After: full suite → 524 passed, 2 skipped, 100% coverage, exit 0, no other warnings surfaced.

…ecation)

anyio 4.15 deprecates anyio.abc.BlockingPortal through a lazy import, and
starlette 1.6.0 (the latest release) still imports that alias at module scope
in testclient.py. Importing fastapi.testclient therefore emits a
DeprecationWarning, and filterwarnings = ["error"] aborts pytest during
collection (exit 2) before any test runs. This broke both our own CI and the
guard-core ecosystem gate's guard-agent consumer job, whose fresh
resolution admits anyio 4.15.x (the dev pin is anyio<4.16 since #53).

Ignore exactly that warning until starlette ships its master fix
(anyio.from_thread.BlockingPortal); the filter is a bridge, not a loophole —
any other warning still fails the suite.
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 2036654a-645f-4880-af14-44ed4b8124bf

📥 Commits

Reviewing files that changed from the base of the PR and between 67886c3 and 575ca31.

📒 Files selected for processing (1)
  • pyproject.toml

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The pytest filterwarnings configuration retains global warning errors and adds an ignore rule for the anyio.abc.BlockingPortal deprecation warning caused by the Starlette test client.

Changes

Pytest warning filter

Layer / File(s) Summary
Configure pytest warning handling
pyproject.toml
The configuration preserves "error" handling and ignores the deprecated anyio.abc.BlockingPortal warning with an explanatory comment.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 575ca

The compatibility filter addresses the known Starlette/AnyIO collection warning while other warnings continue to fail the test suite.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the pytest collection issue, the AnyIO version context, and the targeted BlockingPortal deprecation workaround. It accurately summarizes the main change.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rennf93 rennf93 self-assigned this Sep 11, 2026
@github-actions github-actions Bot added the dependencies pyproject.toml or uv.lock label Sep 11, 2026
@rennf93
rennf93 merged commit 6f8d055 into master Sep 11, 2026
13 of 15 checks passed
@rennf93
rennf93 deleted the fix/anyio-blockingportal-collection branch September 11, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies pyproject.toml or uv.lock

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test suite aborts at collection (exit 2) under anyio >= 4.15: BlockingPortal DeprecationWarning promoted to error

1 participant