test: convert context_aware_server to in-process threads for coverage#2342
Open
perhapzz wants to merge 6 commits intomodelcontextprotocol:mainfrom
Open
test: convert context_aware_server to in-process threads for coverage#2342perhapzz wants to merge 6 commits intomodelcontextprotocol:mainfrom
perhapzz wants to merge 6 commits intomodelcontextprotocol:mainfrom
Conversation
9b80c04 to
40bfd49
Compare
… threads Replace multiprocessing.Process with threading.Thread for the context_aware_server fixture so coverage.py can track server-side code. - Remove 5 pragma: no cover markers now reachable by coverage - Graceful shutdown via server.should_exit instead of proc.kill() - All 61 tests pass, pyright/ruff clean Part of modelcontextprotocol#1678
40bfd49 to
f53793d
Compare
…_aware handler - Add pragma: no branch for ctx.request guards (always truthy in test env) - Add pragma: no cover for unknown tool fallback return (never reached in tests) - Fixes coverage failure: these branches are defensive code paths that cannot be exercised through the test fixtures
Python 3.14 deprecates asyncio.iscoroutinefunction(), which uvicorn calls internally. With pytest's filterwarnings=['error'], this DeprecationWarning becomes an exception that kills the server thread before it can start listening. In multiprocessing mode this was hidden because child processes don't inherit pytest's warning filters. Threading shares the same process, so we need to explicitly suppress DeprecationWarnings in the server thread.
6cba79c to
ff4239d
Compare
On Windows Python 3.13, the ProactorBasePipeTransport.__del__ fires during GC after the threaded uvicorn server shuts down, raising a PytestUnraisableExceptionWarning due to filterwarnings=['error']. Force a GC collection with warnings suppressed so the transport finalizer runs before pytest's unraisable-exception hook can catch it.
On Windows Python 3.13, the ProactorBasePipeTransport finalizer fires during GC after the threaded uvicorn server shuts down, raising PytestUnraisableExceptionWarning. Add a filterwarnings marker to all tests that use the threaded context_aware_server fixture.
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.
Motivation
Part of #1678
The
context_aware_servertest fixture launches a server viamultiprocessing.Process, socoverage.pycannot track its execution. This PR applies the same in-process threading approach to this fixture.Changes
multiprocessing.Processwiththreading.Thread+uvicorn.Serverfor thecontext_aware_serverfixtureserver.should_exit = Trueinstead ofproc.kill()# pragma: no covermarkers:_handle_context_list_tools,_handle_context_call_tool,run_context_aware_server,context_aware_serverfixture,proc.is_alive()guardpyright0 errors,ruff check+ruff formatclean