Repository navigation
test: configure explicit asyncio fixture loop scopes - #17640
dmitry-tokarev-nv merged 1 commit into
Conversation
Set function-scoped fixture loops explicitly and preserve the hello-world server fixture's module loop. Remove the unset-scope warning suppression now that pytest-asyncio no longer emits it. Refs OPS-9043 Signed-off-by: Pranjul Gupta <pranjulgupta0203@gmail.com>
|
👋 Hi Pranjulcr7! Thank you for contributing to ai-dynamo/dynamo. Just a reminder: The 🚀 |
|
/ok to test 584e0de |
dmitry-tokarev-nv
left a comment
There was a problem hiding this comment.
No P0 or P1 found, and this review has no other findings.
Head reviewed: 584e0dee0c5d85fb3c1e56d6171260c7bf1d893e.
Open item: Recipe Check does not run on this pull request, because its path filter does not match the two changed files. The pytest 9.2.0 results below come from local runs.
The head gives the same results as the base, and each new line is needed.
The Recipe Check test command from .github/workflows/pre-merge.yml ran unchanged in each tree, on Python 3.12.9. A small wrapper supplied Kustomize v5.8.1 through kubectl kustomize (kubectl v1.36.3).
| pytest / pytest-asyncio | base 108cbfa758 |
head 584e0dee0c |
head without the new option |
|---|---|---|---|
| 9.2.0 / 1.4.1 | 351 passed | 351 passed | exit 3, INTERNALERROR> pytest.PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset. |
| 9.0.3 / 1.3.0 | 351 passed | 351 passed | 351 passed |
scripts/kustomize-matrix.py check exited 0 in every cell.
A test module imported the real server_process fixture into two async tests, with a stub hello_world.py as the server. A small pytest plugin recorded the loop scope that pytest-asyncio picked.
| tree | 9.2.0 / 1.4.1 | 9.0.3 / 1.3.0 |
|---|---|---|
| base | module loop, 3 passed | module loop, 3 passed |
| head | module loop, 3 passed | module loop, 3 passed |
head without loop_scope="module" |
ScopeMismatch |
ScopeMismatch |
Both tests got the same process, and a third test found the process stopped after module teardown.
A syntax-tree scan of the 1,975 tracked Python files at the head found 28 async fixtures, under every import alias of pytest.fixture and pytest_asyncio.fixture. Only server_process has a caching scope broader than function. The scan found the same 28 fixtures after a merge with main at c10c8797d2, and that merge had no conflicts. A planted module-scoped async fixture without loop_scope ran in a module loop with the base configuration. With the head configuration, it failed at setup with ScopeMismatch. So a future fixture of that kind stops at setup. It does not run in a different loop without notice.
In CI on this head, dynamo-runtime / test / sequential ran lib/bindings/python/tests/test_example_hello_world.py::test_hello_world with pytest 9.0.3, pytest-asyncio 1.3.0 and the new option. The test passed on amd64 and on arm64.
Every CI job that installs pytest-asyncio uses version 1.0 or later, and version 0.24.0 added asyncio_default_fixture_loop_scope. Two jobs run pytest with the root configuration but without pytest-asyncio, and they clear addopts and filterwarnings with --override-ini. In those runs, the new option adds one PytestConfigWarning, and the tests pass on both trees.
Overview
Replace the pytest-asyncio unset-loop-scope warning suppression with explicit fixture loop configuration. Function-scoped async fixtures keep per-test loops, and the hello-world server retains its module-scoped loop.
Key Changes
Two configuration/decorator changes plus one import; no production runtime changes.
pyproject.toml: setasyncio_default_fixture_loop_scope = "function"and remove the unset-scope warning filter added in ci(test): OPS-9043 keep the pytest-asyncio loop scope notice nonfatal under pytest 9.2 #17519. With the option set, pytest-asyncio no longer emits that warning.lib/bindings/python/tests/test_example_hello_world.py: usepytest_asyncio.fixture(scope="module", loop_scope="module")forserver_process. It yields a subprocess handle, so sharing it across per-test event loops preserves its existing lifecycle.An AST audit of all 1,975 tracked Python files found 28 async fixtures. This server fixture is the only one with a cache scope broader than function; the other 27 already use function scope.
Validation
Python 3.13.16 and the CI-qualified Kustomize 5.8.1:
ScopeMismatchon both pairsPytestDeprecationWarningscripts/kustomize-matrix.py checkThe lifecycle probe uses a minimal subprocess and was kept outside the repository; it does not run the full hello-world service. Full runtime/NVIDIA CI remains to be run. Recipe Check's path filter excludes these two changed paths, so its result above is local validation.
Issues and Ongoing Work
Pull Request Checklist
/pr-checklistskill.Summary by CodeRabbit