test(lsp): silence asyncio DeprecationWarning in sync tests#773
Merged
Conversation
Bind a fresh event loop in the four `TestMessageHandling` tests that build futures synchronously, and use `loop.create_future()` instead of bare `asyncio.Future()`. Without this, pytest emits a `DeprecationWarning: There is no current event loop` and the tests will eventually fail outright on Python versions that drop implicit loop creation. Co-Authored-By: AI Assistant <noreply@ai>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the LSP connection unit tests to avoid asyncio deprecation warnings on Python 3.12+ by ensuring synchronous tests have an explicit event loop when creating futures.
Changes:
- Added a
_sync_test_event_loop()context manager to bind a fresh event loop during specific synchronous tests. - Updated affected tests to use
loop.create_future()instead ofasyncio.Future(). - Added an “Under the Hood” changelog entry documenting the test-only adjustment.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tests/unit/lsp/test_lsp_connection.py |
Introduces a sync test event-loop context manager and updates tests to create futures from the bound loop. |
.changes/unreleased/Under the Hood-20260513-085513.yaml |
Changelog entry describing the warning-suppression change in unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jairus-m
approved these changes
May 13, 2026
Collaborator
jairus-m
left a comment
There was a problem hiding this comment.
Ran tests locally - no deprecations!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TestMessageHandling(tests/unit/lsp/test_lsp_connection.py) construct anasyncio.Future()synchronously without a current event loop, which emitsDeprecationWarning: There is no current event loopunder Python 3.12+._sync_test_event_loopcontext manager that binds a fresh loop for the duration of each affected test, and switches toloop.create_future().Test plan
task test:unit— 692 passedtask check— lint, ruff, mypy cleanTestMessageHandlingtests still pass with no warnings🤖 Generated with AI assistance