Anthony Flury <anthony.fl...@btinternet.com> added the comment: No - it isn't related.
In the case of mock_open; it isn't intended to be a simple MagicMock - it is meant to be a mocked version of open, and so to be useful as a testing tool, it should emulate a file as much as possible. When a mock_open is created, you can provide an argument 'read_data' which is meant to be the data from your mocked file, so it is key that the dunder iter method actually returns an iterator. The mock_open implementation already provides special versions of read, readline and readlines methods which use the 'read_data' initial value as the content. Currently though the dunder iter method isn't set at all - so the returned value would currently be an empty iterator (which makes mock_open unable to be used to test idiomatic python : def display(file_name): with open('a.txt', 'r') as fp: for line in fp: print(line) As a trivial example the above code when mock_open is used will be equivalent of opening an empty file, but this code : def display(file_name): with open('a.txt', 'r') as fp: while True: line = readline(fp) if line == '': break print(line) Will work correctly with the data provided to mock_open. Regardless of how and when #33236 is solved - a fix would still be needed for mock_open to make it provide an iterator for the mocked file. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32933> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com