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 077532c
Show file tree
Hide file tree
Showing 3 changed files with 15 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
8 changes: 8 additions & 0 deletions pyfakefs/pytest_tests/pytest_plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 077532c

Please sign in to comment.