Author anthony-flury
Recipients anthony-flury, bbayles, eric.araujo, ezio.melotti, michael.foord, rbcollins
Date 2018-04-06.17:14:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:

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 == '':

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.
Date User Action Args
2018-04-06 17:14:17anthony-flurysetrecipients: + anthony-flury, rbcollins, ezio.melotti, eric.araujo, michael.foord, bbayles
2018-04-06 17:14:17anthony-flurysetmessageid: <>
2018-04-06 17:14:17anthony-flurylinkissue32933 messages
2018-04-06 17:14:17anthony-flurycreate