Author anthony-flury
Recipients anthony-flury
Date 2018-02-24.08:58:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Using the unittest.mock helper mock_open with multi-line read data, although readlines method will work on the mocked open data, the commonly used iterator idiom on an open file returns the equivalent of an empty file.

    from unittest.mock import mock_open

    read_data = 'line 1\nline 2\nline 3\nline 4\n'
    with patch('', mock_open) as mocked:
       with open('a.txt', 'r') as fp:
           assert [l for l in StringIO(read_data)] ==
                  [l for l in fp] 

will fail although it will work on a normal file with the same data, and using [l for l in fp.readlines()] will also work.  

There is a relatively simple fix which I have a working local version - but I don't know how to provide that back to the library - or even if i should.
Date User Action Args
2018-02-24 08:58:38anthony-flurysetrecipients: + anthony-flury
2018-02-24 08:58:38anthony-flurysetmessageid: <>
2018-02-24 08:58:38anthony-flurylinkissue32933 messages
2018-02-24 08:58:38anthony-flurycreate