New submission from Niko <ni...@cendio.com>:
Using 'mock_open' to unit test a code that uses the 'seek()' function for the file object does not work. This would be a great addition for mock_open functionality as this use case happens occasionally. Test file contains: def test_one(self): with patch("builtins.open", mock_open(read_data="#123")): script.main() Example script: def main(): with open('some/file', 'r') as f: print(f.read(1)) f.seek(0) print(f.read(1)) if __name__ == "__main__": main() Output will be: # 1 While the expected output is: # # ---------- messages: 393378 nosy: nikle priority: normal severity: normal status: open title: mock_open does not support the use of 'seek()' type: behavior versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44102> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com