The Python Oracle

Python Mocking of Boolean Function

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC P Beethoven - Piano Sonata No 2 in A

--

Chapters
00:00 Question
00:55 Accepted answer (Score 1)
01:20 Thank you

--

Full question
https://stackoverflow.com/questions/3094...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #python27 #unittesting #mocking

#avk47



ACCEPTED ANSWER

Score 2


From your function here, stream seems to be a class.

Since you create an instance of that class and then you call the open method on that instance, you need to do mock_stream.return_value.open.return_value = False in the test function.