From b6603f604b265f09f66aa1e8db6d788a91b8db7e Mon Sep 17 00:00:00 2001 From: Agnia Sergeyuk Date: Tue, 26 May 2026 12:12:37 +0200 Subject: [PATCH 1/2] AI-generated possible solution for #1317 --- pyfakefs/fake_os.py | 10 ++++++---- pyfakefs/fake_path.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pyfakefs/fake_os.py b/pyfakefs/fake_os.py index 56c1e8ea..e24ff72a 100644 --- a/pyfakefs/fake_os.py +++ b/pyfakefs/fake_os.py @@ -25,6 +25,7 @@ import sys import uuid from contextlib import contextmanager +import threading from stat import ( S_IFREG, S_IFSOCK, @@ -88,7 +89,7 @@ class FakeOsModule: my_os_module = fake_os.FakeOsModule(filesystem) """ - use_original = False + _use_original = threading.local() @staticmethod def dir() -> list[str]: @@ -1468,7 +1469,7 @@ def handle_original_call(f: Callable) -> Callable: @functools.wraps(f) def wrapped(*args, **kwargs): - should_use_original = FakeOsModule.use_original + should_use_original = getattr(FakeOsModule._use_original, "value", False) if not should_use_original and args: self = args[0] @@ -1502,8 +1503,9 @@ def use_original_os(): """Temporarily use original os functions instead of faked ones. Used to ensure that skipped modules do not use faked calls. """ + use_original = getattr(FakeOsModule._use_original, "value", False) try: - FakeOsModule.use_original = True + FakeOsModule._use_original.value = True yield finally: - FakeOsModule.use_original = False + FakeOsModule._use_original.value = use_original diff --git a/pyfakefs/fake_path.py b/pyfakefs/fake_path.py index b4434e05..2c345bd8 100644 --- a/pyfakefs/fake_path.py +++ b/pyfakefs/fake_path.py @@ -46,7 +46,6 @@ if TYPE_CHECKING: from pyfakefs.fake_filesystem import FakeFilesystem - from pyfakefs.fake_os import FakeOsModule def _copy_module(old: ModuleType) -> ModuleType: @@ -599,7 +598,8 @@ def handle_original_call(f: Callable) -> Callable: def wrapped(*args, **kwargs): if args: self = args[0] - should_use_original = self.os.use_original + from pyfakefs.fake_os import FakeOsModule # noqa: F401 + should_use_original = getattr(FakeOsModule._use_original, "value", False) if not should_use_original and self.filesystem.has_patcher: skip_names = self.filesystem.patcher.skip_names if is_called_from_skipped_module( From 58d0833dc19b713c9c53bd4b4b610d3921ce5bc8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 May 2026 10:13:11 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pyfakefs/fake_path.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyfakefs/fake_path.py b/pyfakefs/fake_path.py index 2c345bd8..9d2c704d 100644 --- a/pyfakefs/fake_path.py +++ b/pyfakefs/fake_path.py @@ -599,6 +599,7 @@ def wrapped(*args, **kwargs): if args: self = args[0] from pyfakefs.fake_os import FakeOsModule # noqa: F401 + should_use_original = getattr(FakeOsModule._use_original, "value", False) if not should_use_original and self.filesystem.has_patcher: skip_names = self.filesystem.patcher.skip_names