Side Effects: Another Test
Currently, this is kind of a useless test because, as we saw when we ran it without setting the
.side_effect, it raised the
ConnectionError automatically because I don’t have the holidays API running on my machine. But let’s set another side effect.
As we saw when we first made this
GET request, it returned a
ConnectionError, or rather it raised a
ConnectionError. It didn’t raise a
Timeout error, but we can actually test the
Timeout error by setting a
.side_effect in a test.
And there we
Ran 2 tests and they both succeeded. So this shows that you can use the
.side_effect attribute to assign a side effect of a mocked function, like the
.get() method. Right now, like, you might not see the value of using
It almost feels like you’re cheating in a test. Like, why would you just test, you know, make the
Timeout and then it should just verify it—like, wouldn’t this always raise a
Timeout if you set the
.side_effect to a
Timeout? Well, yes it would.
Become a Member to join the conversation.