Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pyfakefs/fake_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sys
import uuid
from contextlib import contextmanager
import threading
from stat import (
S_IFREG,
S_IFSOCK,
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions pyfakefs/fake_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -599,7 +598,9 @@ 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(
Expand Down