Skip to content

Commit

Permalink
Add workaround for a recursion problem
Browse files Browse the repository at this point in the history
- the problem occurs with pytest under Windows and Python >= 3.12
- this is a workaround until the problem is
  better understood
  • Loading branch information
mrbean-bremen committed Dec 11, 2024
1 parent 195b8de commit e109fdc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ The released versions correspond to PyPI releases.

### Fixes
* fixed a regression in version 5.7.2 that `tempfile` was not patched after pause/resume
(POSIX only, see [#1098](../../issues/1098))4
(POSIX only, see [#1098](../../issues/1098))
* added workaround for a recursion occurring if using pytest under Windows and Python >= 3.12
(see [#1096](../../issues/1096))

### Infrastructure
* run pytest-specific tests for all supported Python versions
Expand Down
7 changes: 5 additions & 2 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,10 @@ def updatecache(self, filename, module_globals=None):
"""Calls the original linecache.updatecache making sure no fake OS calls
are used."""
with use_original_os():
return self.linecache_updatecache(filename, module_globals)
# workaround for updatecache problem with pytest under Windows, see #1096
if not filename.endswith(r"pytest.exe\__main__.py"):
return self.linecache_updatecache(filename, module_globals)
return []

@classmethod
def clear_fs_cache(cls) -> None:
Expand Down Expand Up @@ -1010,7 +1013,7 @@ def start_patching(self) -> None:
self._patching = True
self._paused = False

if sys.version_info >= (3, 13):
if sys.version_info >= (3, 12):
# in linecache, 'os' is now imported locally, which involves the
# dynamic patcher, therefore we patch the affected functions
self.linecache_updatecache = linecache.updatecache
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 @@ -77,3 +77,11 @@ def test_switch_to_linux(fs):
def test_switch_to_macos(fs):
fs.os = OSType.MACOS
assert os.path.exists(tempfile.gettempdir())


def test_updatecache_problem(fs):
# regression test for #1096
filename = r"C:\source_file"
fs.create_file(filename)
with open(filename):
assert True

0 comments on commit e109fdc

Please sign in to comment.