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

TestClient methods return Result, not _ResultBase #2209

Closed
wants to merge 1 commit into from

Conversation

davetapley
Copy link
Contributor

Fixes #2207

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4910dd7) 100.00% compared to head (9c86b93) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2209   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           62        62           
  Lines         6880      6880           
  Branches      1099      1099           
=========================================
  Hits          6880      6880           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@CaselIT
Copy link
Member

CaselIT commented Feb 1, 2024

Thanks, the CI has some failing tests, can you fix them too?

@davetapley
Copy link
Contributor Author

@CaselIT this turned out to be more complicated because of:

return StreamedResult(

That breaks my naive typing, because simulate_request could return StreamedResult.

I could change to -> Union[Result, StreamedResult],
but that doesn't help for #2207 because StreamedResult doesn't implement text or json
(but does explain why it was _ResultBase in the first place).


However: StreamedResult can only be returned from _simulate_request_asgi,
so it would be nice (for my purposes) if I could narrow to just Result (since I'm using WSGI).

I thought I could hint my way around it by adding a TypeGuard to:

if _is_asgi_app(app):
return async_to_sync(

But that doesn't work because an ASGIApp is a WSGIApp 😞

And that led me to realize that what I want on #2207 (text and json) isn't possible so long as:

  1. An ASGIApp is (i.e. subclasses) a WSGIApp, and:
  2. We want the simulate_get, etc. functions to work transparently with WSGI or ASGI applications, because:
  3. Liskov substitution principle

In light of that I'm going to close this and #2207, and open a new discussion to address the underlying issue.

@CaselIT
Copy link
Member

CaselIT commented Feb 1, 2024

let me try something

@CaselIT CaselIT reopened this Feb 1, 2024
@CaselIT
Copy link
Member

CaselIT commented Feb 1, 2024

I can't seem to be able to push an update. I'll create a new PR

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.

TestClient methods are typed to return _ResultBase, but actually return Result
2 participants