Skip to content

Commit

Permalink
Forward unfaked fcntl calls to real module
Browse files Browse the repository at this point in the history
- had been removed accidentally in 5.7.0
- fixes #1074
  • Loading branch information
mrbean-bremen committed Oct 11, 2024
1 parent 16f60b8 commit 305ed2e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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)

0 comments on commit 305ed2e

Please sign in to comment.