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.

Return Value (Part 2)

Tristan on June 20, 2020

How would you set the return value of multiple chained method calls?

Valeriy Pomulev on Aug. 8, 2020

Hello Lee,

Thank you for comprehensive course.

I am wondering why today.weekday() (line 10) worked fine (i.e. returned values in range 0-6) despite you actually mocked the enclosing datetime object ?

I’d expected that it returned None as in previous lessons.

Bartosz Zaczyński RP Team on Aug. 10, 2020

While today is a mocked object, Lee told it to return a predefined datetime instance he created before:

tuesday = datetime(year=2019, month=1, day=1)

 

datetime.today.return_value = tuesday

When he calls datetime.today().weekday(), a legit datetime object, i.e. tuesday, handles the job.

Become a Member to join the conversation.