Sitelet https://github.com/python/cpython/issues/148701
Skip to content

Add missing test coverage for asyncio.graph #148701

Description

@ashm-dev

Code coverage analysis of Lib/asyncio/graph.py reveals several uncovered branches and error-handling blocks. We need to add tests for the following scenarios in test_asyncio/test_graph.py:

  1. Invalid Types:
    • Triggering TypeError by passing a non-Future object to capture_call_graph() and _build_graph_for_future().
  2. Context Errors & Fallbacks:
    • Triggering RuntimeError by calling capture_call_graph() outside of a running event loop without providing a future.
    • Returning None from capture_call_graph() (and subsequently "" from format_call_graph()) when called inside a running event loop, but not within an active task (when no future is provided).
  3. The limit Parameter:
    • Testing the truncation logic using both positive and negative limit values in capture_call_graph() and _build_graph_for_future().
  4. Generator Introspection:
    • Hitting the elif hasattr(coro, 'ag_await') branch in _build_graph_for_future() to test ag_await traversal.
    • Formatting standard (synchronous) generators in format_call_graph() to test the except AttributeError fallback that accesses gi_frame and gi_code.

Linked PRs

Activity

  1. added a commit that references this issue on Apr 17, 2026
  2. added a commit that references this issue on May 12, 2026
  3. moved this from Todo to Done in asyncioon May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions