Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use anyio.from_thread.BlockingPortal in TestClient - #3498

Merged
Kludex merged 4 commits into
Kludex:mainfrom
vyrnsynx:fix-testclient-blockingportal-alias
Sep 5, 2026
Merged

Use anyio.from_thread.BlockingPortal in TestClient#3498
Kludex merged 4 commits into
Kludex:mainfrom
vyrnsynx:fix-testclient-blockingportal-alias

Conversation

@vyrnsynx

@vyrnsynx vyrnsynx commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace anyio.abc.BlockingPortal with anyio.from_thread.BlockingPortal in TestClient. Importing starlette.testclient no longer emits a DeprecationWarning on anyio 4.15+.

Fixes #3497

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Review in cubic

anyio 4.15 deprecated anyio.abc.BlockingPortal. The runtime type alias
in testclient.py evaluated that name on import.

Fixes Kludex#3497
@codspeed-hq

codspeed-hq Bot commented Sep 3, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 7.44%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 239 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation test_multipart[file-512KiB] 2.6 ms 3.2 ms -18.26%
Simulation test_multipart[boundary-like-file] 8.1 ms 9.4 ms -13.28%
Simulation test_urlencoded_form[field-1MiB-64KiB] 9.4 ms 8.4 ms +11.86%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing vyrnsynx:fix-testclient-blockingportal-alias (d4e2950) with main (75735e1)

Open in CodSpeed

@Kludex
Kludex enabled auto-merge (squash) September 5, 2026 07:02
@Kludex
Kludex disabled auto-merge September 5, 2026 07:03
@Kludex
Kludex enabled auto-merge (squash) September 5, 2026 07:03
@Kludex
Kludex merged commit bbee894 into Kludex:main Sep 5, 2026
11 checks passed
prasadus92 added a commit to luminik-io/alfred that referenced this pull request Sep 5, 2026
…tal deprecation (#732)

## Why the pytest matrix went red

Every `pytest (3.11 / 3.12 / 3.13)` job on #731 fails at collection with

```
DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
```

raised from `starlette/testclient.py:53`
(`_PortalFactoryType = Callable[[],
AbstractContextManager[anyio.abc.BlockingPortal]]`)
the moment a test module does `from fastapi.testclient import
TestClient`. Seven
server test modules (`test_batteries_serve`, `test_server`,
`test_server_api_contract`,
`test_server_code_intelligence`, `test_server_static_ui`,
`test_server_usage`,
`test_streaming_endpoints`) never collect, so the whole session is
interrupted.

**What moved, and when.** The workflow installs `pytest`, `fastapi`,
`httpx` and
`httpx2` unpinned via `uv run --with`. The last green run on `main`
(2026-08-23)
resolved anyio 4.14.2. anyio 4.15.0 shipped on 2026-09-02 (4.15.1 on
2026-09-05)
and turned `anyio.abc.BlockingPortal` into a lazily-resolved deprecated
alias that
warns on access. starlette 1.6.0 (2026-08-08, still the latest release,
pulled by
fastapi 0.141.1) reads that alias at import time. With `filterwarnings =
["error"]`
in `pyproject.toml`, the warning is an import-time exception. This is
not a runner
problem: #731 only changes `runs-on`, and the same failure reproduces
locally with
the workflow's exact `uv run` line against `main`. Nothing in this
repo's own code
touches anyio.

## Fix

1. **`pyproject.toml`**: one `filterwarnings` entry that ignores exactly
that
message, of exactly that category, from exactly the
`starlette.testclient`
module. This is a third-party warning with no released fix: starlette
merged
Kludex/starlette#3498 (switches to `anyio.from_thread.BlockingPortal`)
but has
not cut a release that contains it. Once a fixed starlette ships the
entry is a
   no-op and can be dropped; the comment says so.

Why not pin `anyio<4.15` instead: in `dependencies` it would constrain
every
`alfred-os` wheel user for a test-only warning; in the `dev` extra it
would
never be installed, because CI runs `uv run --with ...` without `--extra
dev`;
as a uv constraint it would not help a plain pip venv. The scoped ignore
works
   for every install path and expires on its own.

2. **`tests/test_server.py`**: the collection failure was masking a
second,
unrelated drift. `test_api_memory_lessons_lists_active_lessons`
hard-coded
`valid_until=2026-08-30` and asserted `memory_status == "active"`, but
the
endpoint evaluates expiry against the wall clock, so the test turned red
by
itself on 2026-08-30 on all three Pythons. The expiry is now derived
from
`now + 90 days` and the serialised value is asserted against that same
datetime.

## Verification

- Reproduced with the workflow's exact
`uv run --python X --with pytest --with fastapi --with httpx --with
httpx2 pytest tests/`
on 3.11, 3.12 and 3.13: identical 7 collection errors before the change.
- `--with 'anyio<4.15'` alone also clears collection, confirming which
package drifted.
- After the change the seven server modules collect and pass on 3.11,
3.12 and 3.13.
A full 3.13 run of the suite showed no other failure hiding behind the
collection
error (the only extra red was three release-gate tests that fail solely
under a
local git config with commit signing forced on, and pass with it
neutralised).
- `ruff check` / `ruff format --check` (0.15.22) clean;
`bin/scrub-check.sh` clean.

## Follow-up for #731

#731 needs no change. Once this lands, rebase or re-run its CI
(`gh run rerun <run-id> --failed`) and the pytest matrix should go green
there too.
felixonmars added a commit to felixonmars/archriscv-packages that referenced this pull request Sep 6, 2026
Backport the upstream BlockingPortal alias fix. AnyIO 4.15 deprecates
anyio.abc.BlockingPortal, making starlette.testclient emit a warning
that aborts python-openapi-core test collection with warnings as errors.

Upstream: Kludex/starlette#3498
hyperrealist added a commit to bluesky/scanspec that referenced this pull request Sep 7, 2026
The lock file maintenance bump to anyio 4.15.1 deprecates the
anyio.abc.BlockingPortal alias. starlette's testclient still imports
it, which emits a DeprecationWarning that pyproject.toml's
filterwarnings = "error" turns into a collection error, failing all
test jobs.

Unpin once Kludex/starlette#3498 is released.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BZFFKbxfBT1fUfzGpa8rXA
hyperrealist added a commit to bluesky/scanspec that referenced this pull request Sep 7, 2026
* Lock file maintenance

* Pin anyio<4.15 to fix CI test failures

The lock file maintenance bump to anyio 4.15.1 deprecates the
anyio.abc.BlockingPortal alias. starlette's testclient still imports
it, which emits a DeprecationWarning that pyproject.toml's
filterwarnings = "error" turns into a collection error, failing all
test jobs.

Unpin once Kludex/starlette#3498 is released.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BZFFKbxfBT1fUfzGpa8rXA

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Hiran Wijesinghe <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
wolfgang-aura added a commit to wolfgang-aura/Mailman that referenced this pull request Sep 11, 2026
`--superseded-by` was stored and never shown, so an unfiled run overtaken
upstream read as plain `unsubmitted`. Two such runs are on disk: the starlette
fix superseded by Kludex/starlette#3498 and the mypy#21964 fix superseded by
python/mypy#21966, which the new competitor check found before filing.

Co-Authored-By: Claude Opus 5 <[email protected]>
Upellift99 added a commit to Upellift99/ovispect that referenced this pull request Sep 12, 2026
…ette ships #3498

anyio 4.15 (2026-09-02) deprecates the `anyio.abc.BlockingPortal` alias,
which starlette's TestClient still imports at module load in its latest
release (1.6.0, 2026-08-08). With `filterwarnings = ["error"]` the warning
aborts conftest import: pytest exits with code 4 before running a single
test, on every fresh install since the anyio release. Reproduced locally
by pinning anyio==4.15.1.

Dependencies are current; the fix simply is not published yet: starlette
switched to `anyio.from_thread.BlockingPortal` on master on 2026-09-05
(Kludex/starlette#3498). The ignore is scoped to that one message and
marked to be removed at the first starlette release after 1.6.0.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_0113DEa3m359srdD3TtkNm2n
Upellift99 added a commit to Upellift99/ovispect that referenced this pull request Sep 12, 2026
* feat(ui): preset filter buttons via QUICK_FILTERS

Add a QUICK_FILTERS setting ("Label=needle;…") that renders preset buttons
under the search box. Clicking one fills the search with its needle;
clicking the active one clears it. The active preset is highlighted and
persisted with the other UI preferences.

A needle may hold several |-separated terms matched as OR, and the search
box now accepts the same syntax ("desktop|laptop"), so a single button can
cover a family of clients.

Parsing lives in Settings.quick_filter_list (labels default to the needle,
blanks and duplicate labels dropped, at most 20 entries, labels ≤ 40 chars,
validated at startup). Covered by tests/test_quick_filters.py (parsing,
rendering, HTML escaping) and a Playwright e2e test that exercises the
OR matching, the highlight and the toggle. The e2e `_serve` helper now
accepts Settings overrides for such fixtures.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_0113DEa3m359srdD3TtkNm2n

* fix(ci): ignore the anyio 4.15 BlockingPortal deprecation until starlette ships #3498

anyio 4.15 (2026-09-02) deprecates the `anyio.abc.BlockingPortal` alias,
which starlette's TestClient still imports at module load in its latest
release (1.6.0, 2026-08-08). With `filterwarnings = ["error"]` the warning
aborts conftest import: pytest exits with code 4 before running a single
test, on every fresh install since the anyio release. Reproduced locally
by pinning anyio==4.15.1.

Dependencies are current; the fix simply is not published yet: starlette
switched to `anyio.from_thread.BlockingPortal` on master on 2026-09-05
(Kludex/starlette#3498). The ignore is scoped to that one message and
marked to be removed at the first starlette release after 1.6.0.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_0113DEa3m359srdD3TtkNm2n

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

testclient imports the deprecated anyio.abc.BlockingPortal alias

2 participants