-
Notifications
You must be signed in to change notification settings - Fork 1
Use pytest-asyncio for unittest #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughReplaces anyio-based async test setup with pytest-asyncio. Updates test markers in Changes
Sequence Diagram(s)(Skipped — changes are test configuration and do not alter runtime control flow.) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
tox.ini (1)
14-14
: Pin pytest-asyncio version to ensure compatibility with asyncio_modeWithout a lower bound, tox could pick an older plugin that doesn’t recognize asyncio_mode. Align with pyproject’s extras and avoid surprises by pinning a minimum version.
Apply this diff:
- pytest-asyncio + pytest-asyncio>=0.21.0tests/test_streamable_http.py (2)
79-79
: Optional: With asyncio_mode="auto", the decorator is not strictly requiredSince pytest-asyncio is configured with asyncio_mode="auto", async tests can run without the @pytest.mark.asyncio decorator. Keeping it is fine; remove it if you prefer less noise.
Apply this diff if you want to drop the decorator:
-@pytest.mark.asyncio
142-142
: Nit: Standardize request payload shape for initializeThe first test uses {"params": {}} while this one uses {}. Standardizing helps readability and reduces surprises if send_request’s API tightens.
Apply this diff:
- result = await t.send_request("initialize", {}) + result = await t.send_request("initialize", {"params": {}})
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
pyproject.toml
(1 hunks)tests/test_streamable_http.py
(3 hunks)tox.ini
(1 hunks)
🔇 Additional comments (5)
pyproject.toml (1)
78-78
: pytest-asyncio auto mode enabled — LGTMThis is the right toggle for seamless async test execution with pytest-asyncio. No concerns.
tests/test_streamable_http.py (4)
1-1
: Docstring clarifies test runner — LGTMGood context for contributors that these async tests use pytest-asyncio.
79-119
: Converted to pytest-asyncio — test logic and monkeypatching look correct
- Using @pytest.mark.asyncio aligns with the new config.
- Replacing httpx.AsyncClient with a fake that implements an async context manager is sound.
121-147
: Converted SSE test to pytest-asyncio — LGTMFlow and assertions look good; the fake client correctly simulates an SSE response with aiter_lines().
79-119
: No anyio markers detected in testsConfirmed that there are no occurrences of
@pytest.mark.anyio
or other AnyIO-specific patterns in thetests/
directory. The migration topytest-asyncio
is complete—no further action required.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67 +/- ##
==========================================
- Coverage 55.04% 52.91% -2.13%
==========================================
Files 42 42
Lines 3194 3194
Branches 502 502
==========================================
- Hits 1758 1690 -68
- Misses 1327 1413 +86
+ Partials 109 91 -18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/test_streamable_http.py (1)
82-82
: @pytest.mark.asyncio is redundant with asyncio_mode="auto" (optional cleanup).Given asyncio_mode="auto" in pytest config, you can drop the decorators or set a module-level pytestmark to reduce repetition. If you prefer explicitness, keeping them is fine.
Minimal cleanup (remove per-test decorators):
-@pytest.mark.asyncio async def test_streamable_http_json_initialize(monkeypatch): @@ -@pytest.mark.asyncio async def test_streamable_http_sse_response(monkeypatch):Alternatively, apply one mark for the whole module (add near the imports):
# Apply asyncio marker to all tests in this module pytestmark = pytest.mark.asyncioAlso applies to: 124-124
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
tests/test_streamable_http.py
(3 hunks)
🔇 Additional comments (2)
tests/test_streamable_http.py (2)
1-1
: Good module-level context.Explicitly stating pytest-asyncio usage improves test readability for future maintainers.
9-10
: Guard against incompatible pytest-asyncio versions and ensure it’s declared
- I didn’t find
pytest-asyncio
listed intox.ini
,requirements*.txt
, orpyproject.toml
. Please confirm it’s added as a test dependency.- Once declared, update the import-or-skip to require a minimum version that supports
asyncio_mode="auto"
:-# Skip this module if pytest-asyncio is not available to avoid failing runs -pytest.importorskip("pytest_asyncio") +# Skip this module if pytest-asyncio is unavailable or too old for asyncio_mode="auto" +pytest.importorskip("pytest_asyncio", minversion="0.21")
fixes #62
Summary by CodeRabbit
Tests
Chores
No user-facing changes; functionality and public APIs remain unchanged.