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

Pyfakefs 5.7.2 regression for NamedTemporaryFile #1098

Closed
cal-pratt opened this issue Dec 10, 2024 · 7 comments · Fixed by #1099
Closed

Pyfakefs 5.7.2 regression for NamedTemporaryFile #1098

cal-pratt opened this issue Dec 10, 2024 · 7 comments · Fixed by #1099

Comments

@cal-pratt
Copy link

Describe the bug
It seems that pause/resume functionallity somehow causes NamedTemporaryFile to be double deleted, leading to test failures. This happens in pyfakefs==5.7.2 but not pyfakefs==5.7.1.

How To Reproduce
Example test:

from tempfile import NamedTemporaryFile


def test(fs):
    fs.pause()
    fs.resume()
    with NamedTemporaryFile() as f:
        pass

With crash that looks like this:

$ pytest test.py
============================= test session starts ==============================
platform darwin -- Python 3.11.10, pytest-8.3.3, pluggy-1.5.0
rootdir: 
configfile: pyproject.toml
plugins: pyfakefs-5.7.2, ...
collected 1 item

test.py F                                                                [100%]

=================================== FAILURES ===================================
_____________________________________ test _____________________________________

fs = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x1129c02d0>

    def test(fs):
        fs.pause()
        fs.resume()
>       with NamedTemporaryFile() as f:

.../test.py:7: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../3.11/lib/python3.11/tempfile.py:519: in __exit__
    self.close()
.../3.11/lib/python3.11/tempfile.py:526: in close
    self._closer.close()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <tempfile._TemporaryFileCloser object at 0x112982290>
unlink = <built-in function unlink>

    def close(self, unlink=_os.unlink):
        if not self.close_called and self.file is not None:
            self.close_called = True
            try:
                self.file.close()
            finally:
                if self.delete:
>                   unlink(self.name)
E                   FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/41/ptjvny1d7tsbn59t_ywv2y2m0000gq/T/tmpzytjbc5o'

.../3.11/lib/python3.11/tempfile.py:463: FileNotFoundError
=========================== short test summary info ============================
FAILED test.py::test - FileNotFoundError: [Errno 2] No such file or directory...
============================== 1 failed in 0.53s ===============================

Your environment

macOS-14.7.1-arm64-arm-64bit
Python 3.11.10 (main, Sep  7 2024, 01:03:31) [Clang 15.0.0 (clang-1500.3.9.4)]
pyfakefs 5.7.2
pytest 8.3.3

Note, I can also reproduce this on a linux VM.

@mrbean-bremen
Copy link
Member

Thanks! I will see if I can fix this or revert the related change (this was a performance improvement, not a fix or feature, so it would have no further impact). Obviously missing some tests here...

@mrbean-bremen
Copy link
Member

For the record: I can confirm that the problem happens with Python 3.10 and 3.11, but not with 3.12 and 3.13 (tested under WSL). Under Windows it obviously doesn't happen, as the code in question is POSIX-specific (as was the change that broke it).

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Dec 10, 2024
- fixes pytest-dev#1098 (regression in version 5.7.2)
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Dec 10, 2024
- fixes pytest-dev#1098 (regression in version 5.7.2)
@mrbean-bremen
Copy link
Member

Should be fixed in main branch now - can you please check? If it works for you, I will make another patch release.

@cal-pratt
Copy link
Author

Nice I will try this out today and get back to you!

@cal-pratt
Copy link
Author

Retested against a clone of origin/main installed. All looks good!
Thanks for getting to this so quickly! 😄

@mrbean-bremen
Copy link
Member

Thanks for reporting!

@mrbean-bremen
Copy link
Member

FYI: Just made a patch release with the fix. I was waiting for feedback for another fix, but decided to go ahead without that.

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

Successfully merging a pull request may close this issue.

2 participants