freezegun icon indicating copy to clipboard operation
freezegun copied to clipboard

potential feature request; flag to apply to file attributes?

Open tommyjcarpenter opened this issue 4 years ago • 1 comments

Fully reproducible python file:

import tempfile
import os
import pathlib
import datetime

from freezegun import freeze_time


@freeze_time("2020-06-06 06:06:06")
def foo():
    with tempfile.TemporaryDirectory() as testrepo:
        fpath = os.path.join(testrepo, "foo.txt")
        with open(fpath, "w") as f:
            f.write("asdfasdf")

        fname = pathlib.Path(fpath)

        # get the modified time of the file
        lmt = datetime.datetime.fromtimestamp(fname.stat().st_mtime)

        print(lmt)


foo()

In this file, lmt is unaffected by freezegun.

I would assume this does not freeze becuase this is calling OS level APIs that are not patched. But with mock_open I wonder if this could be achieved? IE if you could do something like with freeze_time(xxx, mock_file_attrs=True) which takes care of the necessary mocking of file attributes? This may not be possible, just wondering.

tommyjcarpenter avatar Apr 21 '21 16:04 tommyjcarpenter

+1

zerocewl avatar Oct 11 '21 12:10 zerocewl