falcon icon indicating copy to clipboard operation
falcon copied to clipboard

feat(testing): add `__rich__` representation to `Result`

Open krikera opened this issue 7 months ago • 5 comments

Summary of Changes

Added a __rich__ method to the Result class in the testing module to enable better integration with the Rich library. When a user has the Rich library installed and uses rich.print() or similar functionality, they'll now see a nicely formatted representation of the Falcon Result object.

Related Issues

Similar to #2044

Pull Request Checklist

  • [x] Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
    • The implementation affects the Result class which is used by both WSGI and ASGI code paths.
  • [x] Added tests for changed code.
    • Created test_rich.py to validate the markdown output from the __rich__ method.
  • [x] Performed automated tests and code quality checks by running tox.
  • [x] Prefixed code comments with GitHub nick and an appropriate prefix.
  • [x] Coding style is consistent with the rest of the framework.
  • [x] Updated documentation for changed code.
    • [x] Added docstrings for any new classes, functions, or modules.
    • [x] Updated docstrings for any modifications to existing code.
    • [x] Updated both WSGI and ASGI docs (where applicable).
    • [x] Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • [x] Updated all relevant supporting documentation files under docs/.
    • [x] A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • [x] Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • [x] Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/, with the file name format {issue_number}.{fragment_type}.rst. (Run towncrier --draft to ensure it renders correctly.)

Fixes #2457

krikera avatar Jun 04 '25 07:06 krikera

Codecov Report

Attention: Patch coverage is 4.16667% with 23 lines in your changes missing coverage. Please review.

Project coverage is 99.70%. Comparing base (11974e9) to head (1ec1ad3). Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
falcon/testing/client.py 4.16% 23 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##            master    #2458      +/-   ##
===========================================
- Coverage   100.00%   99.70%   -0.30%     
===========================================
  Files           64       64              
  Lines         7775     7799      +24     
  Branches      1078     1084       +6     
===========================================
+ Hits          7775     7776       +1     
- Misses           0       23      +23     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 04 '25 07:06 codecov[bot]

@CaselIT I'm not too opinionated about the exact verbosity level either, but I do think we should keep this roughly in sync with __repr__.

vytas7 avatar Jun 04 '25 20:06 vytas7

not familiar with the Rich library, does it support other hooks? like is there a __very_right__ method we can implement too to be more verbose?

CaselIT avatar Jun 04 '25 21:06 CaselIT

Maybe __filthy_rich__? 😈

If we want to do more, see the link from the issue's description: https://rich.readthedocs.io/en/stable/protocol.html#console-customization: there are also __rich_console__ and __rich_measure__ methods. Not sure if the use of these actually implies more verbosity, they just give you more advanced control.

(I'm not a heavy user either FWIW, I just know that library is fairly popular.)

vytas7 avatar Jun 04 '25 21:06 vytas7

those seem used for other features. let's go with your version, but maybe we could include the header names?

CaselIT avatar Jun 05 '25 07:06 CaselIT

Hi again @krikera, just checking whether you plan to continue working on this PR?

vytas7 avatar Jun 20 '25 19:06 vytas7

Closing this one in the absence of response, but feel free to reopen unless anyone else grabs this @krikera!

vytas7 avatar Jun 29 '25 18:06 vytas7