question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

future feature request - ability to mock exceptions with a response

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kbakkcommented, Mar 22, 2022

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.

0reactions
beliaev-maksimcommented, Mar 22, 2022

@kbakk I see the issue now, thanks it is not inability to raise an exception but an ability to redirect, right?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found