Skip to content
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

Make it easier to debug close reason assertions #3659

Conversation

DoctorJohn
Copy link
Member

@DoctorJohn DoctorJohn commented Oct 6, 2024

Description

Before this PR, Pytest could not display the diff between the expected and actual close reason because the assertion was hidden behind an assert_reason method.
Now, Pytest shows a pretty diff, making it easier to debug unexpected WebSocket close reasons in tests.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Summary by Sourcery

Enhance WebSocket test assertions by replacing the assert_reason method with a close_reason property, enabling Pytest to show detailed diffs for assertion errors, thus improving the debugging process.

Enhancements:

  • Replace the assert_reason method with a close_reason property to improve the readability of assertion errors in WebSocket tests.

Tests:

  • Update WebSocket test assertions to use the close_reason property instead of the assert_reason method, allowing Pytest to display a detailed diff for easier debugging.

Copy link
Contributor

sourcery-ai bot commented Oct 6, 2024

Reviewer's Guide by Sourcery

This pull request enhances the debugging experience for WebSocket close reason assertions in tests. It replaces the assert_reason method with a direct comparison of the close_reason property, allowing Pytest to display a more informative diff when assertions fail.

Updated class diagram for WebSocketClient classes

classDiagram
    class WebSocketClient {
        +int close_code()
        +bool closed()
        +Optional~str~ close_reason
    }

    class AioHttpClient {
        +int close_code()
        +bool closed()
        +Optional~str~ close_reason
    }

    class AsgiClient {
        +int close_code()
        +bool closed()
        +Optional~str~ close_reason
    }

    class ChannelsClient {
        +int close_code()
        +bool closed()
        +Optional~str~ close_reason
    }

    class LitestarClient {
        +int close_code()
        +bool closed()
        +Optional~str~ close_reason
    }

    WebSocketClient <|-- AioHttpClient
    WebSocketClient <|-- AsgiClient
    WebSocketClient <|-- ChannelsClient
    WebSocketClient <|-- LitestarClient
Loading

File-Level Changes

Change Details Files
Replace assert_reason method with close_reason property
  • Remove assert_reason method from WebSocketClient classes
  • Add close_reason property to WebSocketClient classes
  • Update all test assertions to use assert ws.close_reason == ... instead of ws.assert_reason(...)
tests/http/clients/aiohttp.py
tests/http/clients/asgi.py
tests/http/clients/channels.py
tests/http/clients/litestar.py
tests/http/clients/base.py
Update WebSocket close reason assertions in test files
  • Replace ws.assert_reason(...) calls with assert ws.close_reason == ...
tests/websockets/test_graphql_transport_ws.py
tests/websockets/test_websockets.py
tests/websockets/test_graphql_ws.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @DoctorJohn - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codecov bot commented Oct 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.82%. Comparing base (34b40d4) to head (524d9fa).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3659   +/-   ##
=======================================
  Coverage   96.82%   96.82%           
=======================================
  Files         503      503           
  Lines       33409    33414    +5     
  Branches     5583     5587    +4     
=======================================
+ Hits        32348    32354    +6     
  Misses        830      830           
+ Partials      231      230    -1     

Copy link

codspeed-hq bot commented Oct 6, 2024

CodSpeed Performance Report

Merging #3659 will not alter performance

Comparing DoctorJohn:improve-close-reason-assertions (524d9fa) with main (d7e8a9b)

Summary

✅ 15 untouched benchmarks

@patrick91 patrick91 merged commit 3484480 into strawberry-graphql:main Oct 6, 2024
110 checks passed
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.

2 participants