Skip to content

Actual file system change when using pathlib.Path.open() rather than open(pathlib.Path) #1178

@scaramallion

Description

@scaramallion

Describe the bug
I'm getting an actual file system change when using pyfakefs to modify an existing file using pathlib.Path.open() rather than open(pathlib.Path).

How To Reproduce

from pathlib import Path

p = Path(__file__).parent / "foo.bin"
with open(p, "wb") as f:
    f.write(b"\x00\x01\x02\x03")

def test_pffs_open(fs):
    fs.add_real_file(p, read_only=False)
    # Next test passes with open(p, "wb") instead
    with p.open("wb") as f:
        f.write(b"\xDE\xAD\xBE\xEF")

def test_actual():
    with p.open("rb") as f:
        assert f.read() == b"\x00\x01\x02\x03"

Your environment
Please run the following in the environment where the problem happened and
paste the output.

Linux-6.8.0-60-generic-x86_64-with-glibc2.39
Python 3.10.18 (main, Jun  4 2025, 08:56:00) [GCC 13.3.0]
pyfakefs 5.8.0
pytest 8.4.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions