Skip to content

Add missing test coverage for asyncio.graph #148701

@ashm-dev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions