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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ The released versions correspond to PyPI releases.

* fixed a crash if the stack limit was set to a low value
(see [#1313](https://github.com/pytest-dev/pyfakefs/issues/1313))
* fixed `os.ftruncate` to inspect the `FakeFileWrapper` returned by
`get_open_file(fd)`
(see [#1331](https://github.com/pytest-dev/pyfakefs/issues/1331))

## [Version 6.2.0](https://pypi.python.org/pypi/pyfakefs/6.2.0) (2026-04-12)

Expand Down
7 changes: 3 additions & 4 deletions pyfakefs/fake_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,11 +1019,10 @@ def ftruncate(self, fd: int, length: int) -> None:
Raises:
OSError: if the file descriptor is invalid
"""
file_object = self.filesystem.get_open_file(fd).get_object()
if isinstance(file_object, FakeFileWrapper):
file_object.size = length
else:
file_handle = self.filesystem.get_open_file(fd)
if not isinstance(file_handle, FakeFileWrapper):
self.filesystem.raise_os_error(errno.EBADF)
file_handle.get_object().size = length

def access(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyfakefs/tests/fake_os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2974,7 +2974,7 @@ def test_ftruncate(self):
self.create_file(file_path, contents="0123456789012345")

fd = self.os.open(file_path, os.O_RDWR)
self.os.truncate(fd, 10)
self.os.ftruncate(fd, 10)
self.assertEqual(10, self.os.stat(file_path).st_size)
with self.open(file_path, encoding="utf8") as f:
self.assertEqual("0123456789", f.read())
Expand Down