diff --git a/CHANGES.md b/CHANGES.md index 293a8734..53e44f25 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/pyfakefs/fake_file.py b/pyfakefs/fake_file.py index 746bd575..e1e3e66d 100644 --- a/pyfakefs/fake_file.py +++ b/pyfakefs/fake_file.py @@ -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: @@ -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. diff --git a/pyfakefs/tests/fake_open_test.py b/pyfakefs/tests/fake_open_test.py index 15623494..d0f7216f 100644 --- a/pyfakefs/tests/fake_open_test.py +++ b/pyfakefs/tests/fake_open_test.py @@ -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")