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: '_FakeAccessor' object has no attribute 'owner' #629

Closed
saxocellphone opened this issue Aug 23, 2021 · 3 comments · Fixed by #630
Closed

AttributeError: '_FakeAccessor' object has no attribute 'owner' #629

saxocellphone opened this issue Aug 23, 2021 · 3 comments · Fixed by #630
Labels

Comments

@saxocellphone
Copy link

saxocellphone commented Aug 23, 2021

Describe the bug
Getting E AttributeError: '_FakeAccessor' object has no attribute 'owner' when running with pytest. More specifically, happens in this function in pathlib.py

# pathlib.py:1228 gives error
def owner(self):
    """
    Return the login name of the file owner.
    """
    return self._accessor.owner(self)

How To Reproduce
Run a pytest with code containing this line

owner = Path(file_path).owner()

I have tried running on python 3.9.6, python 3.6.14. It works with the ladder, but not the former.

macOS-10.16-x86_64-i386-64bit
Python 3.9.6 (v3.9.6:db3ff76da1, Jun 28 2021, 11:49:53)
[Clang 6.0 (clang-600.0.57)]
pyfakefs-4.5.0

EDIT:
Dug a bit deeper, seems like somewhere in time Pathlib changed the implementation of the owner function. This is the old implementation:

def owner(self):
    """
    Return the login name of the file owner.
    """
    import pwd
    return pwd.getpwuid(self.stat().st_uid).pw_name

The new implementation have the owner attribute in the accessor, so a mock is needed for that

@mrbean-bremen
Copy link
Member

Thanks for the report and the investigation! As we heavily rely on the pathlib implementation itself, this is something that happens from time to time with new Python versions. We are obviously missing some test here, as the CI tests actually run with Python 3.9.6 (among others) and pass.

@mrbean-bremen
Copy link
Member

Both owner and group are moved to accessors - both have to be mocked. The actual implementation has not changed, so we can probably just use that in the fake accessor.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Aug 26, 2021
- return the current user/group name under Posix
- raises NotImplementedError under Windows
- fixes pytest-dev#629
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Aug 26, 2021
- return the current user/group name under Posix
- raises NotImplementedError under Windows
- fixes pytest-dev#629
mrbean-bremen added a commit that referenced this issue Aug 27, 2021
- return the current user/group name under Posix
- raises NotImplementedError under Windows
- fixes #629
@mrbean-bremen
Copy link
Member

@saxocellphone - shall be fixed in master now, please check!

github-actions bot pushed a commit that referenced this issue Aug 27, 2021
…rent user/group name under Posix - raises NotImplementedError under Windows - fixes #629
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