future feature request - ability to mock exceptions with a response
See original GitHub issueI don’t think this is possible in the current library, so for the future, it would be nice to be able to mock exceptions that have a response attribute.
As an example…
We have a flow of redirects:
A -> 301 redirect -> B
B -> 301 redirect -> C
C -> 301 redirect -> D
D -> 200 html
And I need to mock a ConnectionError, or otherwise, on C.
In a real-world situations, the error raised by requests
has a response
attribute, which will have the .url
and .history
attributes which can be inspected. This information is unfortunately gone under responses
.
I don’t see this as being possible in the current design. It’s probably not possible at all. I did want to note this as a wishlist item if anyone ever has an idea.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Can't mock Future error after first build · Issue #327 - GitHub
It works for the first future from initState but a exception is caught after the button tap. ══╡ EXCEPTION CAUGHT BY FLUTTER TEST...
Read more >Requests Mock Documentation - Read the Docs
The requests-mock library at its core is simply a transport adapter that can be preloaded with responses that are returned.
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
In this article, we'll cover multiple mock interfaces, listening invocations, matchers, and argument captors, and see firsthand how Mockito makes your tests ...
Read more >Stubbing and Mocking with Mockito and JUnit - Semaphore CI
Learn how to create true unit tests by mocking all external dependencies in your JUnit classes with the help of Mockito.
Read more >Feature request response email templates - LiveAgent
Answer feature request emails professionally and kindly regardless of the (good or bad) news you're delivering to your customers.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Both are possible today/supported as demonstrated with my example. I think having an example in the docs on how to simulate redirects would be helpful.
I do see that OP is asking for the exceptions to be richer. My example don’t contain the properties that request would add to the exception - especially the request and response objects. Today, it seems one have to construct the exception to have it yourself, before passing it as with the body arg.
@kbakk I see the issue now, thanks it is not inability to raise an exception but an ability to redirect, right?