New submission from Damien Nadé <bugzilla-pyt...@livna.org>:

While we can iterate on a mock_open handle, it is not actually possible to 
perform a next() on it.

My use case is the following: I have a file with a one-line header that I want 
to skip. So, roughly, my code is like

    with open(filename, 'r') as my_file:
        confirm_header(next(my_file))
        for line in my_file:
            do_something(line)

And while writing a unit test on this code, the handle returned by 
mock_open(read_data=my_read_data) returns a mock instead of the first line of 
my_read_data.

----------
components: Library (Lib)
messages: 343177
nosy: Anvil
priority: normal
severity: normal
status: open
title: make unittest.mock.mock_open honor next()
type: enhancement
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to