Skip to content

Conversation

Agent-Hellboy
Copy link
Owner

@Agent-Hellboy Agent-Hellboy commented Aug 20, 2025

fixes #62

Summary by CodeRabbit

  • Tests

    • Migrated async tests to use pytest-asyncio and added guards to skip when unavailable, improving async test reliability.
    • Updated test markers to rely on pytest-asyncio’s event loop handling.
  • Chores

    • Enabled automatic asyncio mode in test configuration and added asyncio test dependency for CI/test environments.

No user-facing changes; functionality and public APIs remain unchanged.

Copy link
Contributor

coderabbitai bot commented Aug 20, 2025

Walkthrough

Replaces anyio-based async test setup with pytest-asyncio. Updates test markers in tests/test_streamable_http.py, adds pytest-asyncio to tox.ini testenv deps, and sets asyncio_mode = "auto" in pyproject.toml. No production code changes.

Changes

Cohort / File(s) Summary
Pytest configuration
pyproject.toml
Added [tool.pytest.ini_options] asyncio_mode = "auto" for pytest-asyncio event loop handling.
Async test migration
tests/test_streamable_http.py
Replaced anyio markers/fixture with pytest.mark.asyncio; added module docstring and pytest.importorskip("pytest_asyncio"); test logic unchanged.
Tox test env dependencies
tox.ini
Added pytest-asyncio to testenv:tests deps; commands unchanged.

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

Objective Addressed Explanation
Use pytest-asyncio to write unit test for async code (#62)

Poem

I twitch my ears at tests that run,
Loops now managed, neatly spun;
Pytest-asyncio hops in place,
Tox brings treats for every case.
A little rabbit does a happy dance. 🥕🐇

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch use-asyncio-inside-unittest

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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_mode

Without 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.0
tests/test_streamable_http.py (2)

79-79: Optional: With asyncio_mode="auto", the decorator is not strictly required

Since 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 initialize

The 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 87f91c2 and b45a4b9.

📒 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 — LGTM

This 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 — LGTM

Good 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 — LGTM

Flow and assertions look good; the fake client correctly simulates an SSE response with aiter_lines().


79-119: No anyio markers detected in tests

Confirmed that there are no occurrences of @pytest.mark.anyio or other AnyIO-specific patterns in the tests/ directory. The migration to pytest-asyncio is complete—no further action required.

Copy link

codecov bot commented Aug 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.91%. Comparing base (87f91c2) to head (09a195a).
⚠️ Report is 22 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.asyncio

Also 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.

📥 Commits

Reviewing files that changed from the base of the PR and between b45a4b9 and 09a195a.

📒 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 in tox.ini, requirements*.txt, or pyproject.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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use pytest-asyncio to write unit test for async code.
1 participant