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.getxattr should raise OSError(ENODATA) for non-existent extended attributes #971

Closed
vector-of-bool opened this issue Mar 11, 2024 · 1 comment · Fixed by #978
Closed
Labels

Comments

@vector-of-bool
Copy link

Describe the bug
The faked os.getxattr returns None if the extended attribute does not exist (and is documented as such). The standard os.getxattr either returns bytes or raises an OSError from the underlying syscall. The getxattr syscall fails with ENODATA if the attribute name is legal but is unset, and fails with ENOTSUP if the attribute name is illegal.

How To Reproduce

def read_nonexistent_xattr(s: Path):
    s.write_text("file content")
    # Non-existent attribute:
    with pytest.raises(OSError) as exc:
        os.getxattr(s, "user.nonesuch_attribute")
    assert exc.value.errno == errno.ENODATA
    # Invalid attribute:
    with pytest.raises(OSError) as exc:
        os.getxattr(s, "invalid attribute name")
    assert exc.value.errno == errno.ENOTSUP

def test_realfs():
    read_nonexistent_xattr(Path("file.txt"))

def test_fakefs(fs):
    read_nonexistent_xattr(Path("file.txt"))

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

$ python -c "import platform; print(platform.platform())"
Linux-6.7.6-arch1-1-x86_64-with-glibc2.39
$ python -c "import sys; print('Python', sys.version)"
Python 3.11.7 (main, Jan 29 2024, 16:03:57) [GCC 13.2.1 20230801]
$ python -c "from pyfakefs import __version__; print('pyfakefs', __version__)"
pyfakefs 5.4.dev0
$ python -c "import pytest; print('pytest', pytest.__version__)"
pytest 7.2.0
@mrbean-bremen
Copy link
Member

Thanks! Keep in mind that real xattr support will not added to pyfakefs, but at least the behavior shall be as expected.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Mar 13, 2024
- no tests for real OS (extended atributes not enabled in CI)
- fixes pytest-dev#971
mrbean-bremen added a commit that referenced this issue Mar 13, 2024
- no tests for real OS (extended atributes not enabled in CI)
- fixes #971
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants