Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ 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
* fixes a regression that caused unfaked `fcntl` calls to fail (see [#1074](../../issues/1074))

## [Version 5.7.0](https://pypi.python.org/pypi/pyfakefs/5.7.0) (2024-08-10)
Adds official Python 3.13 support, improves OS emulation behavior.

Expand Down
6 changes: 5 additions & 1 deletion pyfakefs/fake_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def lockf(
pass

def __getattribute__(self, name):
"""Forwards any unfaked calls to the standard fcntl module."""
"""Prevents patching of skipped modules."""
fs: FakeFilesystem = object.__getattribute__(self, "filesystem")
fnctl_module = object.__getattribute__(self, "_fcntl_module")
if fs.patcher:
Expand All @@ -193,3 +193,7 @@ def __getattribute__(self, name):
return getattr(fnctl_module, name)

return object.__getattribute__(self, name)

def __getattr__(self, name):
"""Forwards any unfaked calls to the standard fcntl module."""
return getattr(self._fcntl_module, name)
22 changes: 22 additions & 0 deletions pyfakefs/pytest_tests/fake_fcntl_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

if sys.platform == "linux":
import fcntl

def test_unpatched_attributes_are_forwarded_to_real_fs(fs):
# regression test for #1074
with open("lock_file", "a+") as lock_file:
fcntl.flock(lock_file, fcntl.LOCK_SH)
fcntl.flock(lock_file, fcntl.LOCK_UN)