Skip to content

Commit

Permalink
Make sure tempfile is patched after resume
Browse files Browse the repository at this point in the history
- fixes pytest-dev#1098 (regression in version 5.7.2)
  • Loading branch information
mrbean-bremen committed Dec 10, 2024
1 parent f7db85c commit 19fd4ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,13 @@ def test_pause_resume_without_patcher(self):
with self.assertRaises(RuntimeError):
fs.resume()

def test_that_tempfile_is_patched_after_resume(fs):
"""Regression test for #1098"""
fs.pause()
fs.resume()
with tempfile.NamedTemporaryFile():
pass


class PauseResumePatcherTest(fake_filesystem_unittest.TestCase):
def test_pause_resume(self):
Expand Down

0 comments on commit 19fd4ac

Please sign in to comment.