Mock out requests in TestRequest unit tests#1794
Conversation
|
Lol looks like the service is back up again. I still think it's worthwhile to remove dependencies on external services from unit tests so I'll keep this PR open to hear what people think! |
There was a problem hiding this comment.
Let's mock this request to "headers.jsontest.com" as well?
|
Thanks for fixing this @freddyaboulton! Agreed that this is definitely the better approach. I noticed a couple of things:
|
|
Thanks for fixing this @freddyaboulton! Agreed that this is definitely the better approach. I noticed a couple of things:
|
1 similar comment
|
Thanks for fixing this @freddyaboulton! Agreed that this is definitely the better approach. I noticed a couple of things:
|
2ffe7af to
277b546
Compare
| client_response: Request = await Request( | ||
| method=Request.Method.GET, | ||
| url="http://headers.jsontest.com/", | ||
| url="very_real_url.com", |
There was a problem hiding this comment.
Changing the url so that it's clear that we're mocking
|
Thank you for the review @abidlabs ! Completely agree with your comments - I mocked out the remaining requests and applied the mock to the class. This is good for another review now! |
|
Very clean, thanks for addressing the suggestions @freddyaboulton! |
|
Sounds good! actually there is a similar library for this which I like, it mocks the request call and you don't mock your code at all. I would suggest we use it, but @freddyaboulton's approach works as well! The library is aioresponses and there is a pytest plugin . |
|
@farukozderim Thank you for bringing up that library. I'll file an issue to switch to that to get this merged in. I think there's lots of room to improve how we write tests (#1784) |
Description
Requests unit tests were failing because
https://reqres.in/api/usersis unavailable. See this PR for an example: #1785This PR mocks out the calls to that api to make the tests pass and not have to rely on external services
Checklist: