Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The released versions correspond to PyPI releases.
* route some pseudo-devices to the system instead of patching them; this ensures
that `os.urandom` and related functions work correctly with PyPy
(see [#1300](https://github.com/pytest-dev/pyfakefs/issues/1300))
* fake file `seek` method did not return the location in the file
(see [#1304](https://github.com/pytest-dev/pyfakefs/issues/1304))

## [Version 6.1.6](https://pypi.python.org/pypi/pyfakefs/6.1.6) (2026-03-18)
Follow-up bugfix release for 6.1.5.
Expand Down
3 changes: 2 additions & 1 deletion pyfakefs/fake_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ def _flush_related_files(self) -> None:
):
open_file._sync_io()

def seek(self, offset: int, whence: int = 0) -> None:
def seek(self, offset: int, whence: int = 0) -> int:
"""Move read/write pointer in 'file'."""
self._check_open_file()
if not self.open_modes.append:
Expand All @@ -1005,6 +1005,7 @@ def seek(self, offset: int, whence: int = 0) -> None:
self._read_whence = whence
if not self.is_stream:
self.flush()
return self.tell()

def tell(self) -> int:
"""Return the file's current position.
Expand Down
8 changes: 8 additions & 0 deletions pyfakefs/tests/fake_open_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,14 @@ def test_seek_flushes(self):
f0.seek(3)
self.assertEqual(4, self.os.path.getsize(file_path))

def test_seek_returns_location(self):
# Regression test for #1304
file_path = self.make_path("foo")
with self.open(file_path, "w", encoding="utf8") as f0:
f0.write("test")
result = f0.seek(3)
self.assertEqual(3, result)

def test_truncate_flushes(self):
# Regression test for #291
file_path = self.make_path("foo")
Expand Down
Loading