Skip to content

Commit ef60cdb

Browse files
committed
Fixed a crash if the stack limit was too low
- we need to pass the wanted stack limit
1 parent 9f9cc01 commit ef60cdb

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
The released versions correspond to PyPI releases.
33
`pyfakefs` versions follow [Semantic Versioning](https://semver.org/).
44

5+
## Unreleased
6+
7+
### Fixes
8+
* fixed a crash if the stack limit was set to a low value
9+
(see [#1313](https://github.com/pytest-dev/pyfakefs/issues/1313))
10+
511
## [Version 6.2.0](https://pypi.python.org/pypi/pyfakefs/6.2.0) (2026-04-12)
612
Changes the MRO for file wrappers.
713

pyfakefs/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def starts_with(path, string):
511511
if not skip_names and not check_open_code:
512512
return False
513513

514-
stack = traceback.extract_stack()
514+
stack = traceback.extract_stack(limit=6)
515515

516516
# handle the case that we try to call the original `open_code`
517517
# (since Python 3.12)

pyfakefs/tests/fake_open_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,19 @@ def test_file_class(self):
10631063
assert isinstance(f, io.BufferedIOBase)
10641064
assert f.read() == b"test"
10651065

1066+
def test_stacklimit(self):
1067+
"""Regression test for #1313 - handle reduced stack limit"""
1068+
old_tracebacklimit = (
1069+
sys.tracebacklimit if hasattr(sys, "tracebacklimit") else None
1070+
)
1071+
sys.tracebacklimit = 2
1072+
try:
1073+
file_path = self.make_path("foo")
1074+
with self.open(file_path, "w") as f:
1075+
f.write("test")
1076+
finally:
1077+
sys.tracebacklimit = old_tracebacklimit
1078+
10661079

10671080
class RealFileOpenTest(FakeFileOpenTest):
10681081
def use_real_fs(self):

0 commit comments

Comments
 (0)