testing-cabal / mock

The Python mock library

Home Page:https://docs.python.org/dev/library/unittest.mock.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mock_open does not support seek

domanchi opened this issue · comments

Example:

$ cat foobar
some content here
$ cat example.py
import mock


def foobar():
    with open('foobar') as f:
        print(f.read())
        f.seek(0)
        print(f.read())


def mocked_foobar():
    m = mock.mock_open(read_data='blah')
    with mock.patch(
        'builtins.open',
        m,
    ):
        foobar()


if __name__ == '__main__':
    foobar()
    mocked_foobar()
$ python example.py
some content here

some content here

blah

From my initial investigations, it looks pretty hard to change, because it seems only line-based file operations are supported.

This repo is only for issues that are specific to the backport.
Please report issues with mock in the upstream bug tracker at https://bugs.python.org/.
Once issues are fixed upstream, they can be backported here.