django - Python Mocking of Boolean Function -


so have begun working mock library perform unit testing. ran across problem mysterious me.

when call below code stream.open() evaluates true, seems returning mock object rather false value.

test code

@patch('module.lib.stream') def test_error_raised(self, mock_stream):     mock_stream.open.return_value = false     self.assertraises(ioerror, get_query, 618) 

called function

def get_query(id):     id = str(id)     fpath = os.path.join(         path, '{0}.pdf'.format(id))     stream = stream()     if not stream.open(fpath):         raise ioerror("no file found")     list = map(foo, stream.getdata())     first_entry = list[0]     target_entries = list[1:]     return first_entry, target_entries 

is there way mock function?

from function here, stream seems class.

since create instance of class , call open method on instance, need mock_stream.return_value.open.return_value = false in test function.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -