Can't use timeout setting in register_uri or direct requests
Bug #1650858 reported by
Meet
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
requests-mock |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
Not able to use
with requests_
m.head("https:/
# and also
m.register_
It throws:
TypeError: Too many arguments provided. Unexpected arguments timeout.
Is there any way to make mock the server to respond after a given amount of time?
description: | updated |
To post a comment you must log in.
So yea, the error I think is fairly explanatory that timeout isn't a vaild argument. I'm not sure i would want to add it either, adding a pause for a web response is a fairly unusual situation for a unit test as you'll be stuck waiting for the pause.
You can however do it yourself pretty easily.
In times I've wanted to test an actual timeout i've done
m.head('https:/ /www.google. com', exc=requests. Timeout)
which will trigger the same exception requests does when it times out. If you actually want to wait you could do:
def response_ wait(request, context):
time.sleep(15)
return u''
m.head('https:/ /www.google. com', text=response_wait, status_code=404)
More on dynamic responses: http:// requests- mock.readthedoc s.io/en/ latest/ response. html#dynamic- response
Does that satisfy your question?