This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author anthony-flury
Recipients anthony-flury
Date 2018-02-24.08:58:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519462718.87.0.467229070634.issue32933@psf.upfronthosting.co.za>
In-reply-to
Content
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('builtins.open', 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.
History
Date User Action Args
2018-02-24 08:58:38anthony-flurysetrecipients: + anthony-flury
2018-02-24 08:58:38anthony-flurysetmessageid: <1519462718.87.0.467229070634.issue32933@psf.upfronthosting.co.za>
2018-02-24 08:58:38anthony-flurylinkissue32933 messages
2018-02-24 08:58:38anthony-flurycreate