Repository navigation
test: make the serverless suite clean under -W error on 3.14 - #768
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the serverless test-hygiene changes.
No open issues 🎉
What changed in this PR
This PR improves serverless test hygiene for Python 3.14 runs with -W error, without changing SDK runtime behavior.
Changes:
- Match synchronous and asynchronous mocks to real APIs and strengthen cleanup assertions.
- Close leaked coroutines and HTTP sessions, and replace deprecated coroutine inspection.
- Add a download-test-class warning filter for the third-party
backoffdeprecation.
| File | Description |
|---|---|
tests/test_serverless/test_utils/test_download.py |
Scope the backoff warning exemption to the download test class. |
tests/test_serverless/test_scale_mirror.py |
Avoid creating an unawaited fitness-check coroutine during mocked startup. |
tests/test_serverless/test_modules/test_http.py |
Close the client session with an async context manager. |
tests/test_serverless/test_modules/test_fitness/test_system_checks.py |
Correct writer mocks, assert awaited closure, and use inspect.iscoroutinefunction. |
tests/test_serverless/test_modules/test_fitness/test_gpu_integration.py |
Dispose of the coroutine received by the simulated timeout. |
tests/test_serverless/test_modules/test_fitness/test_gpu_checks.py |
Correct process mocks and assert process termination and awaited reaping. |
Review effort: Balanced
f7ed211 to
dfab4a6
Compare
dfab4a6 to
7d8ed5c
Compare
Run with the plugin-default warning handling (-W error, unraisable exceptions enabled), nine serverless tests failed on Python 3.14. They were test hygiene problems, not SDK bugs: - AsyncMock children for synchronous APIs (Process.kill, StreamWriter.close, fitness run_fitness_checks patch) produced never-awaited coroutines. Use MagicMock for the synchronous parts and assert the awaited ones. - Patching asyncio.wait_for with a side effect leaked the un-awaited communicate() coroutine; the replacement now closes it. - An aiohttp ClientSession was never closed; use async with. - asyncio.iscoroutinefunction is deprecated; use inspect's. - backoff (third party) still calls the deprecated asyncio API when decorating; ignore that single warning on the download test class only.
7d8ed5c to
94595c3
Compare
|
Kimi review posted: #768 (review) How to ask for a Kimi review: GitHub: request @justinwlin as a reviewer, or comment |
justinwlin
left a comment
There was a problem hiding this comment.
Kimi review, round 1
Verdict: Approved. 0 Critical, 0 High, 0 Medium, 1 Low → approved.
Next step: deanq merges.
Context: Fixes un-awaited coroutines and deprecated asyncio APIs in five serverless test files so the suite stays clean on Python 3.14 under -W error.
Findings
- Low: The PR body lists an aiohttp
ClientSessionfix ("useasync withfor the client session") that is not in this diff —test_http.pyalready hadasync withat the merge-base, so that fix shipped earlier. Please update the description; the other body claims check out.
Other reviewers, what was run, nits
- Ran:
python3.14 -m pytest tests/test_serverless -W erroron macOS 3.14.6 → parent commit: 8 failed (un-awaited coroutines + the backoffasyncio.iscoroutinefunctiondeprecation); PR head: 747 passed, 1 skipped, 50s. The "fails before, clean after" claim reproduces (9 vs 8 and 686 vs 747 are platform differences). - Verified the class mark in
test_download.pyis load-bearing, not redundant:pytest.ini's global iscoroutinefunction ignore does not protect against command-line-W error(command-line filters outrank ini filters), and the download tests fail at the parent commit without the mark. The two agents' "redundant decorator" read is refuted by the run above. - Copilot review ("no open issues"): no actionable claims to engage.
- Nit
tests/test_serverless/test_utils/test_download.py:73-78: mark + comment duplicate_ignore_backoff_deprecationintests/test_serverless/test_utils/test_cleanup.py:78-82(same magic string twice pluspytest.ini:9); a shared helper or conftest-level mark would keep them in sync. - Nit
tests/test_serverless/test_modules/test_fitness/test_gpu_integration.py:187:awaitable.close()wouldAttributeErrorif a Task/Future were ever passed to the patchedasyncio.wait_for; safe today (gpu.py:151passes a plain coroutine), agetattr(awaitable, "close", None)guard would make it robust. - Not checked: backoff's pinned version (the deprecation call comes from backoff decorating
download_fileinrp_download.py:147); exact Linux failure count.
To get a new review, re-request it or comment 'watcher, review'. If you push new commits, we review again by ourselves 30 minutes after the last push.
Kimi (moonshotai/Kimi-K3) · round 1 · 2 review agents (correctness, quality) · ~15 min · automated review, a human owns the final call. New commits are checked every 5 min and get an automatic re-review of the changes since this round. How to ask for a Kimi review: GitHub: request @justinwlin as a reviewer, or comment @justinwlin watcher, review on the PR. Slack: DM @justin.lin Watcher, review <PR link>. New commits get an automatic re-review 30 min after the last push. Stop it: DM Watcher, stop <PR link>.
Summary
Nine serverless tests failed on Python 3.14 (Linux) with
-W error. They are test hygiene problems, not SDK bugs. This makes the suite clean there before 3.14 strictness is relied on in CI. It still passes on 3.10 and 3.13.Root cause
AsyncMockstood in for synchronous APIs (Process.kill,StreamWriter.close), so calling them created coroutines that were never awaited.asyncio.wait_forwith a side effect dropped thecommunicate()coroutine without awaiting it, which leaked into a later test.asyncio.runnever awaited it.aiohttp.ClientSessionin a test was never closed.asyncio.iscoroutinefunction.backoff(third party) calls the same deprecated API when it decorates the download function.Fix
MagicMockfor synchronous parts,AsyncMockonly for real coroutines, and assertions that the awaited ones were awaited.wait_forcloses the coroutine it receives.async withfor the client session;inspect.iscoroutinefunctionin the test.filterwarningsignore scoped to the download test class, because the warning comes frombackoff.pytest.iniis unchanged.Tests
pytest tests/test_serverless -W error: 9 failed before, 686 passed after.