Skip to content

Conversation

@jlowin
Copy link
Owner

@jlowin jlowin commented Oct 5, 2025

Replaces subprocess-based server tests with in-process async servers using asyncio context managers. This dramatically improves test performance and provides proper tracebacks when errors occur, making debugging significantly easier.

Migrates 19 fixtures across 10 test files from run_server_in_process() to the simpler run_server_async() pattern, eliminating the overhead of spawning separate processes while maintaining all existing functionality.

@marvin-context-protocol marvin-context-protocol bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. tests labels Oct 5, 2025
@strawgate
Copy link
Collaborator

Do we actually need to use anyio for this? When I did this in my projects, removing asyncio_default_fixture_loop_scope = "session" and asyncio_default_test_loop_scope = "session" was enough to be able to create, yield, and connect to running servers.

Anyway, looks great

@jlowin
Copy link
Owner Author

jlowin commented Oct 11, 2025

@strawgate I'll investigate, would love if that was the case

@jlowin
Copy link
Owner Author

jlowin commented Oct 18, 2025

I learned Anthropic uses anyio extensively internally so got remotivated to look at this again

- Convert run_server_async from anyio task group pattern to asyncio.create_task with async context manager
- Remove task_group fixture from conftest
- Update all test fixtures to use async with run_server_async pattern
- Remove TaskGroup imports from all test files
- Tests now work with pytest-asyncio instead of pytest-anyio
@jlowin jlowin changed the title Use anyio as testing backend to radically simplify remote MCP testing Replace subprocess tests with in-process async servers Oct 19, 2025
@jlowin
Copy link
Owner Author

jlowin commented Oct 19, 2025

@strawgate you were right, got everything working with asyncio, no need for anyio in tests! I will however take a look at replacing some asyncio primitives with anyio ones in the library in the future just for compatibility, but this feels great.

@jlowin jlowin merged commit 3321644 into main Oct 19, 2025
10 checks passed
@jlowin jlowin deleted the anyio branch October 19, 2025 14:47
@jlowin jlowin added this to the 2.13.0 milestone Oct 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality. For issues and smaller PR improvements. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants