Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'FakeFcntlModule' object has no attribute 'LOCK_SH' (Also 'LOCK_UN' and 'LOCK_EX') #1074

Closed
sj98ta opened this issue Oct 11, 2024 · 5 comments · Fixed by #1075

Comments

@sj98ta
Copy link

sj98ta commented Oct 11, 2024

Describe the bug
After updating from pyfakefs 5.6.0 to 5.7.0 the following error occurs on flock with fcntl.LOCK_SH, fcntl.LOCK_UN and LOCK_EX.

The error does not occur on version 5.6.0

self = <pyfakefs.fake_io.FakeFcntlModule object at 0x7f237a9ba760>, name = 'LOCK_SH'

    def __getattribute__(self, name):
        """Forwards any unfaked calls to the standard fcntl module."""
        fs: FakeFilesystem = object.__getattribute__(self, "filesystem")
        fnctl_module = object.__getattribute__(self, "_fcntl_module")
        if fs.patcher:
            if is_called_from_skipped_module(
                skip_names=fs.patcher.skip_names,
                case_sensitive=fs.is_case_sensitive,
            ):
                # remove the `self` argument for FakeOsModule methods
                return getattr(fnctl_module, name)
    
>       return object.__getattribute__(self, name)
E       AttributeError: 'FakeFcntlModule' object has no attribute 'LOCK_SH'

How To Reproduce

import fcntl
from os import path


def lock():
    with open('lock_file', 'a+') as lock_file:
        fcntl.flock(lock_file, fcntl.LOCK_SH)
        fcntl.flock(lock_file, fcntl.LOCK_UN)

def test_lock(fs):
    lock()

Your environment
Please run the following in the environment where the problem happened and
paste the output.

python -c "import platform; print(platform.platform())"
python -c "import sys; print('Python', sys.version)"
python -c "from pyfakefs import __version__; print('pyfakefs', __version__)"
python -c "import pytest; print('pytest', pytest.__version__)"
python -c "import platform; print(platform.platform())"
python -c "import sys; print('Python', sys.version)"
python -c "from pyfakefs import __version__; print('pyfakefs', __version__)"
python -c "import pytest; print('pytest', pytest.__version__)"
Linux-6.10.11-200.fc40.x86_64-x86_64-with-glibc2.39
Python 3.9.16 (main, Sep  6 2024, 09:21:47) 
[GCC 14.2.1 20240801 (Red Hat 14.2.1-1)]
pyfakefs 5.7.0
pytest 8.3.3

@mrbean-bremen
Copy link
Member

Thanks! I can't think of any changes in the last version that would cause that, but obviously there is something I miss...

@mrbean-bremen
Copy link
Member

Ok, found the problem - I did indeed miss this during the review, and there was no test in place that caught that..

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Oct 11, 2024
- had been removed accidentally in 5.7.0
- fixes pytest-dev#1074
@mrbean-bremen
Copy link
Member

Should be fixed in main now, please check!
I'll probably wait a couple of days, in case something else comes up, and make a patch release.

@sj98ta
Copy link
Author

sj98ta commented Oct 12, 2024

I confirmed that it now works as expect. Thanks for the quick fix!

@mrbean-bremen
Copy link
Member

FYI: I made the patch release yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants