Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncating a file with os.truncate does not change its contents #545

Closed
ollien opened this issue Aug 13, 2020 · 1 comment
Closed

Truncating a file with os.truncate does not change its contents #545

ollien opened this issue Aug 13, 2020 · 1 comment
Labels

Comments

@ollien
Copy link

ollien commented Aug 13, 2020

Describe the bug
When calling os.truncate on a file that has been created in the fakefs, the contents are left unchanged

How To Reproduce

import os
from pyfakefs.fake_filesystem_unittest import Patcher


patcher = Patcher()
patcher.setUp()

PATH = "/some/path/to/test"
os.makedirs(os.path.dirname(PATH))

with open(PATH, "w") as f:
    f.write("Hello")

os.truncate(PATH, 0)
with open(PATH, "r") as f:
    print(f.read())

patcher.tearDown()

This should print out an empty string, but instead, it prints Hello. Removing pyfakefs, the correct behavior is observed. I separately observed this bug with the pytest fixture, as well.

Your enviroment

Darwin-19.6.0-x86_64-i386-64bit
Python 3.6.5 (default, May 18 2020, 15:15:10) 
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.32.59)]
pyfakefs 4.1.0
@mrbean-bremen
Copy link
Member

Thanks! I have to admit that I was ignorant of os.truncate (never used it myself), and pyfakefs has the same problem... This has not been implemented, and apparantly has not been noticed so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants