Skip to content

Commit 305ed2e

Browse files
committed
Forward unfaked fcntl calls to real module
- had been removed accidentally in 5.7.0 - fixes #1074
1 parent 16f60b8 commit 305ed2e

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ The released versions correspond to PyPI releases.
1212
* the default for `FakeFilesystem.shuffle_listdir_results` will change to `True` to reflect
1313
the real filesystem behavior
1414

15+
## Unreleased
16+
17+
### Fixes
18+
* fixes a regression that caused unfaked `fcntl` calls to fail (see [#1074](../../issues/1074))
19+
1520
## [Version 5.7.0](https://pypi.python.org/pypi/pyfakefs/5.7.0) (2024-08-10)
1621
Adds official Python 3.13 support, improves OS emulation behavior.
1722

pyfakefs/fake_io.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def lockf(
181181
pass
182182

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

195195
return object.__getattribute__(self, name)
196+
197+
def __getattr__(self, name):
198+
"""Forwards any unfaked calls to the standard fcntl module."""
199+
return getattr(self._fcntl_module, name)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
import sys
14+
15+
if sys.platform == "linux":
16+
import fcntl
17+
18+
def test_unpatched_attributes_are_forwarded_to_real_fs(fs):
19+
# regression test for #1074
20+
with open("lock_file", "a+") as lock_file:
21+
fcntl.flock(lock_file, fcntl.LOCK_SH)
22+
fcntl.flock(lock_file, fcntl.LOCK_UN)

0 commit comments

Comments
 (0)