Side Effects as an Iterable (Part 1)
We have this
Timeout exception imported. So we can set the
.side_effect as not just this callable, but a list, and the first side effect is a
Timeout and then the second one is a call to our
.log_request() function, which mocks a successful response.
And then in our test, we can say
with self.assertRaises(Timeout): we will call
get_holidays(). So again, this is saying that when we call
get_holidays(), we expect it to raise a
We can say
assert requests.get.—and remember, this is a
Mock object, so we have this attribute called
.call_count, and that should be
2. Let’s save that and we will open up a terminal. Whoops, I had a typo here—
requests. We’ll save that, open up a terminal, let’s clear the screen, and we’re going to run our test cases again.
Become a Member to join the conversation.