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

os.access() is not properly faked, wrong signature since python3.3 #585

Closed
ArminGruner opened this issue Feb 3, 2021 · 7 comments
Closed
Labels

Comments

@ArminGruner
Copy link

Describe the bug
Signature of os.access() (since Python3.3) is:

os.access = access(path, mode, *, dir_fd=None, effective_ids=False, follow_symlinks=True)

If some code uses the "effective_ids" feature, it does not work when using pyfakefs because the "os.access" function in fake_filesystem.py::FakeOsModule::access() does not match the signature:

def access(self, path, mode, *, dir_fd=None, follow_symlinks=True):

How To Reproduce

import os

def test_fakefs(fs):
    file_path = '/test/file.txt'
    assert not os.access(file_path, os.R_OK)
    fs.create_file(file_path)
    assert os.access(file_path, os.R_OK)

def test_fakefs_effective_ids(fs):
    file_path = '/test/file.txt'
    assert not os.access(file_path, os.R_OK, effective_ids=True)
    fs.create_file(file_path)
    assert os.access(file_path, os.R_OK, effective_ids=True)
» pytest test_os_access.py

```» pytest test_os_access.py
===================================== test session starts =====================================
platform freebsd12 -- Python 3.7.9, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /usr/home/armin/git-repos/link-m/py-linkm, inifile: tox.ini
plugins: mongo-2.0.0, mock-3.5.1, Faker-5.6.1, faker-2.0.0, pyfakefs-4.3.3
collected 2 items                                                                             

test_os_access.py .F                                                                    [100%]

========================================== FAILURES ===========================================
__________________________________ test_fakefs_effective_ids __________________________________

fs = <pyfakefs.fake_filesystem.FakeFilesystem object at 0x803f6ce10>

    def test_fakefs_effective_ids(fs):
        file_path = '/test/file.txt'
>       assert not os.access(file_path, os.R_OK, effective_ids=True)
E       TypeError: access() got an unexpected keyword argument 'effective_ids'

/usr/home/armin/git-repos/link-m/py-linkm/test_os_access.py:11: TypeError
=================================== short test summary info ===================================
FAILED test_os_access.py::test_fakefs_effective_ids - TypeError: access() got an unexpected ...
================================= 1 failed, 1 passed in 1.05s =================================

Your environment
Please run the following and paste the output.

python -c "import platform; print(platform.platform())"
python -c "import sys; print('Python', sys.version)"
python -c "from pyfakefs.fake_filesystem import __version__; print('pyfakefs', __version__)"

FreeBSD-12.1-RELEASE-p10-amd64-64bit-ELF
Python 3.7.9 (default, Dec 3 2020, 01:19:24)
[Clang 8.0.1 (tags/RELEASE_801/final 366581)]
pyfakefs 4.3.3

@mrbean-bremen
Copy link
Member

Good point. I'll probably just add the argument for now, without it having an effect, as we don't really support guid/uid permissions (apart from uid 0 being root). Do you need to have it any functionality?

@ArminGruner
Copy link
Author

ArminGruner commented Feb 3, 2021

Hi, thanks for the instant reply.

I think it's fine to just accept the argument, but not switching test behaviour!

I was just discovering the mismatch when testing a function decorated with pidfile from the pid python package (https://github.com/trbs/pid/). It uses os.access() under the umbrella, and unfortunately uses the named effective_ids argument.

@mrbean-bremen
Copy link
Member

Ok, thanks - will do this in this case in a moment.

@mrbean-bremen
Copy link
Member

Should work now in master.

@ArminGruner
Copy link
Author

Thanks for the fix! I confirm that using master from github works for me now!

@mrbean-bremen
Copy link
Member

Can you live with master, or do you need a patch release?

@ArminGruner
Copy link
Author

Hi, thanks for asking!
I'm fine waiting for any release train.
I've pinned the commit hash in my tox.ini ;-)

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

No branches or pull requests

2 participants