From 305ed2e992fb0f6047a2a77ac6118f9a9de8c3de Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Fri, 11 Oct 2024 19:16:15 +0200 Subject: [PATCH] Forward unfaked fcntl calls to real module - had been removed accidentally in 5.7.0 - fixes #1074 --- CHANGES.md | 5 +++++ pyfakefs/fake_io.py | 6 +++++- pyfakefs/pytest_tests/fake_fcntl_test.py | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 pyfakefs/pytest_tests/fake_fcntl_test.py diff --git a/CHANGES.md b/CHANGES.md index fee281ec..2a940274 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/pyfakefs/fake_io.py b/pyfakefs/fake_io.py index 0c756a5d..6d5b67c1 100644 --- a/pyfakefs/fake_io.py +++ b/pyfakefs/fake_io.py @@ -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: @@ -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) diff --git a/pyfakefs/pytest_tests/fake_fcntl_test.py b/pyfakefs/pytest_tests/fake_fcntl_test.py new file mode 100644 index 00000000..b566b558 --- /dev/null +++ b/pyfakefs/pytest_tests/fake_fcntl_test.py @@ -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)