From 077532cc96a971d09b5cb560bc23f5aa6079c53c Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Tue, 10 Dec 2024 20:56:10 +0100 Subject: [PATCH] Make sure tempfile is patched after resume - fixes #1098 (regression in version 5.7.2) --- CHANGES.md | 6 ++++++ pyfakefs/fake_filesystem_unittest.py | 1 + pyfakefs/pytest_tests/pytest_plugin_test.py | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 521fb7cc..18673032 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,12 @@ The released versions correspond to PyPI releases. * the default for `FakeFilesystem.shuffle_listdir_results` will change to `True` to reflect the real filesystem behavior +## Unreleased + +### Fixes +* fixed a regression in version 5.7.2 that `tempfile` was not patched after pause/resume + (POSIX only, see [#1098](../../issues/1098)) + ## [Version 5.7.2](https://pypi.python.org/pypi/pyfakefs/5.7.2) (2024-12-01) Fixes some problems with patching. diff --git a/pyfakefs/fake_filesystem_unittest.py b/pyfakefs/fake_filesystem_unittest.py index f272cefd..7730df2d 100644 --- a/pyfakefs/fake_filesystem_unittest.py +++ b/pyfakefs/fake_filesystem_unittest.py @@ -125,6 +125,7 @@ def stop_patching(self): tempfile._TemporaryFileCloser.close = self.tempfile_cleanup # type: ignore[module-attr] else: tempfile._TemporaryFileCloser.cleanup = self.tempfile_cleanup # type: ignore[module-attr] + self.tempfile_cleanup = None # reset the cached tempdir in tempfile tempfile.tempdir = None diff --git a/pyfakefs/pytest_tests/pytest_plugin_test.py b/pyfakefs/pytest_tests/pytest_plugin_test.py index 22aa37c0..6a4b963b 100644 --- a/pyfakefs/pytest_tests/pytest_plugin_test.py +++ b/pyfakefs/pytest_tests/pytest_plugin_test.py @@ -55,6 +55,14 @@ def test_pause_resume_contextmanager(fs): assert os.path.exists(fake_temp_file.name) +def test_that_tempfile_is_patched_after_resume(fs): + """Regression test for #1098""" + fs.pause() + fs.resume() + with tempfile.NamedTemporaryFile(): + pass + + def test_use_own_io_module(fs): filepath = "foo.txt" with open(filepath, "w") as f: