Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Side Effects as an Iterable (Part 2)

Yanxin Wang on May 15, 2020

According to docs on side_effect, when an iterable is passed in to side_effect, it must yield either a value to be returned from the call to the mock or an exception instance.

Chris James on May 17, 2020

I’m sorry but this lesson is a hot mess! There’s something to be said about watching experienced developers mess up and persist, it’s important to dispel the myth of the god like creator. (Watch me code Twitch streams for example) Not reading the manual carefully before recording a lesson… This course needs a redo, or at least this lesson.

alistairjames on July 5, 2020

The bonus lesson on how to explore your way out of a hole was great!

Sam Martin on Aug. 27, 2020

I’m inclined to agree with Chris. In a previous lesson you had a name clash with something else called calendar which may have been an issue that some-one following the tutorial would have had anyway if they didn’t follow your file naming exactly, so that made sense to leave in. But not properly testing the behaviour of your demo beforehand and leaving it in the final video isn’t good enough for a paid service, and is very much not in line with the quality of the videos elsewhere on this site which are excellent in this respect.

Charles on Sept. 23, 2020

Rather than the interator being exhausted, it appears that you can’t use a function in a side_effect iterable.

If you pass in an iterable, it is used to retrieve an iterator which must yield a value on every call. This value can either be an exception instance to be raised, or a value to be returned from the call to the mock (DEFAULT handling is identical to the function case).

docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.side_effect

Am I just reading the docs wrong?

Become a Member to join the conversation.