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

Test failures in python 3.11 #677

Closed
AndrewAmmerlaan opened this issue May 18, 2022 · 6 comments · Fixed by #681
Closed

Test failures in python 3.11 #677

AndrewAmmerlaan opened this issue May 18, 2022 · 6 comments · Fixed by #681

Comments

@AndrewAmmerlaan
Copy link

Describe the bug
With python 3.11 several tests are failing, some files that should not exist appear to exist, and some files that should exist return No such file or directory:

=================================================================================== FAILURES ===================================================================================
____________________________________________________________ AdditionalSkipNamesTest.test_fake_path_does_not_exist3 ____________________________________________________________

self = <pyfakefs.tests.fake_filesystem_unittest_test.AdditionalSkipNamesTest testMethod=test_fake_path_does_not_exist3>

def test_fake_path_does_not_exist3(self):
self.fs.create_file('foo')
>       self.assertFalse(
pyfakefs.tests.import_as_example.check_if_exists3('foo'))
E       AssertionError: True is not false

pyfakefs/tests/fake_filesystem_unittest_test.py:378: AssertionError
____________________________________________________________ AdditionalSkipNamesTest.test_fake_path_does_not_exist7 ____________________________________________________________

self = <pyfakefs.tests.fake_filesystem_unittest_test.AdditionalSkipNamesTest testMethod=test_fake_path_does_not_exist7>

def test_fake_path_does_not_exist7(self):
self.fs.create_file('foo')
>       self.assertFalse(
pyfakefs.tests.import_as_example.check_if_exists7('foo'))
E       AssertionError: True is not false

pyfakefs/tests/fake_filesystem_unittest_test.py:398: AssertionError
_________________________________________________________ AdditionalSkipNamesModuleTest.test_fake_path_does_not_exist3 _________________________________________________________

self = <pyfakefs.tests.fake_filesystem_unittest_test.AdditionalSkipNamesModuleTest testMethod=test_fake_path_does_not_exist3>

def test_fake_path_does_not_exist3(self):
self.fs.create_file('foo')
>       self.assertFalse(
pyfakefs.tests.import_as_example.check_if_exists3('foo'))
E       AssertionError: True is not false

pyfakefs/tests/fake_filesystem_unittest_test.py:432: AssertionError
_________________________________________________________ AdditionalSkipNamesModuleTest.test_fake_path_does_not_exist7 _________________________________________________________

self = <pyfakefs.tests.fake_filesystem_unittest_test.AdditionalSkipNamesModuleTest testMethod=test_fake_path_does_not_exist7>

def test_fake_path_does_not_exist7(self):
self.fs.create_file('foo')
>       self.assertFalse(
pyfakefs.tests.import_as_example.check_if_exists7('foo'))
E       AssertionError: True is not false

pyfakefs/tests/fake_filesystem_unittest_test.py:452: AssertionError
________________________________________________________ FakePathlibFileObjectPropertyTest.test_chmod_no_followsymlinks ________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_chmod_no_followsymlinks>

@unittest.skipIf(sys.version_info < (3, 10),
"follow_symlinks argument new in Python 3.10")
def test_chmod_no_followsymlinks(self):
self.skip_if_symlink_not_supported()
file_stat = self.os.stat(self.file_path)
link_stat = self.os.lstat(self.file_link_path)
if os.chmod not in os.supports_follow_symlinks or IS_PYPY:
with self.assertRaises(NotImplementedError):
>               self.path(self.file_link_path).chmod(0o444,
follow_symlinks=False)

pyfakefs/tests/fake_pathlib_test.py:404: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

def chmod(self, mode, *, follow_symlinks=True):
"""
Change the permissions of the path, like os.chmod().
"""
>       os.chmod(self, mode, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/test.py'

/usr/lib/python3.11/pathlib.py:1130: FileNotFoundError
________________________________________________________________ FakePathlibFileObjectPropertyTest.test_exists _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_exists>

def test_exists(self):
self.skip_if_symlink_not_supported()
>       self.assertTrue(self.path(self.file_path).exists())
E       AssertionError: False is not true

pyfakefs/tests/fake_pathlib_test.py:281: AssertionError
________________________________________________________________ FakePathlibFileObjectPropertyTest.test_is_dir _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_is_dir>

def test_is_dir(self):
self.skip_if_symlink_not_supported()
self.assertFalse(self.path(
self.file_path).is_dir())
>       self.assertTrue(self.path(
self.make_path('home/jane')).is_dir())
E       AssertionError: False is not true

pyfakefs/tests/fake_pathlib_test.py:299: AssertionError
________________________________________________________________ FakePathlibFileObjectPropertyTest.test_is_file ________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_is_file>

def test_is_file(self):
self.skip_if_symlink_not_supported()
>       self.assertTrue(self.path(
self.make_path('home/jane/test.py')).is_file())
E       AssertionError: False is not true

pyfakefs/tests/fake_pathlib_test.py:312: AssertionError
______________________________________________________________ FakePathlibFileObjectPropertyTest.test_is_symlink _______________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_is_symlink>

def test_is_symlink(self):
self.skip_if_symlink_not_supported()
self.assertFalse(self.path(
self.make_path('home/jane/test.py')).is_symlink())
self.assertFalse(self.path(
self.make_path('home/jane')).is_symlink())
>       self.assertTrue(self.path(
self.make_path('john')).is_symlink())
E       AssertionError: False is not true

pyfakefs/tests/fake_pathlib_test.py:331: AssertionError
_______________________________________________________ FakePathlibFileObjectPropertyTest.test_iterdir_in_unreadable_dir _______________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_iterdir_in_unreadable_dir>, subtype = 13, expression = <class 'list'>
args = (<generator object Path.iterdir at 0x7f0bbd359e00>,), kwargs = {}

def assert_raises_os_error(self, subtype, expression, *args, **kwargs):
"""Asserts that a specific subtype of OSError is raised."""
try:
>           expression(*args, **kwargs)

pyfakefs/tests/test_utils.py:87: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/some_dir')

def iterdir(self):
"""Iterate over the files in this directory.  Does not yield any
result for the special paths '.' and '..'.
"""
>       for name in os.listdir(self):
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/some_dir'

/usr/lib/python3.11/pathlib.py:929: FileNotFoundError

During handling of the above exception, another exception occurred:

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_iterdir_in_unreadable_dir>

def test_iterdir_in_unreadable_dir(self):
self.check_posix_only()
dir_path = self.make_path('some_dir')
file_path = self.os.path.join(dir_path, 'some_file')
self.create_file(file_path)
self.os.chmod(dir_path, 0o000)
iter = self.path(dir_path).iterdir()
if not is_root():
>           self.assert_raises_os_error(errno.EACCES, list, iter)

pyfakefs/tests/fake_pathlib_test.py:448: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyfakefs/tests/test_utils.py:93: in assert_raises_os_error
self.assertEqual(subtype, exc.errno)
E   AssertionError: 13 != 2
________________________________________________________________ FakePathlibFileObjectPropertyTest.test_lchmod _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_lchmod>

def test_lchmod(self):
self.skip_if_symlink_not_supported()
file_stat = self.os.stat(self.file_path)
link_stat = self.os.lstat(self.file_link_path)
if not hasattr(os, "lchmod"):
with self.assertRaises(NotImplementedError):
>               self.path(self.file_link_path).lchmod(0o444)

pyfakefs/tests/fake_pathlib_test.py:388: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3.11/pathlib.py:1137: in lchmod
self.chmod(mode, follow_symlinks=False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

def chmod(self, mode, *, follow_symlinks=True):
"""
Change the permissions of the path, like os.chmod().
"""
>       os.chmod(self, mode, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/test.py'

/usr/lib/python3.11/pathlib.py:1130: FileNotFoundError
______________________________________________________________ FakePathlibFileObjectPropertyTest.test_lstat_posix ______________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_lstat_posix>

@unittest.skipIf(is_windows, 'POSIX specific behavior')
def test_lstat_posix(self):
>       self.check_lstat(len(self.file_path))

pyfakefs/tests/fake_pathlib_test.py:366: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyfakefs/tests/fake_pathlib_test.py:357: in check_lstat
stat_result = self.path(self.file_link_path).lstat()
/usr/lib/python3.11/pathlib.py:1161: in lstat
return self.stat(follow_symlinks=False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/test.py')

def stat(self, *, follow_symlinks=True):
"""
Return the result of the stat() system call on this path, like
os.stat() does.
"""
>       return os.stat(self, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/test.py'

/usr/lib/python3.11/pathlib.py:1011: FileNotFoundError
_________________________________________________________________ FakePathlibFileObjectPropertyTest.test_stat __________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_stat>

def test_stat(self):
self.skip_if_symlink_not_supported()
file_stat = self.os.stat(self.file_path)

>       stat_result = self.path(self.file_link_path).stat()

pyfakefs/tests/fake_pathlib_test.py:344: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/test.py')

def stat(self, *, follow_symlinks=True):
"""
Return the result of the stat() system call on this path, like
os.stat() does.
"""
>       return os.stat(self, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/test.py'

/usr/lib/python3.11/pathlib.py:1011: FileNotFoundError
______________________________________________________ FakePathlibFileObjectPropertyTest.test_stat_file_in_unreadable_dir ______________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_stat_file_in_unreadable_dir>, subtype = 13
expression = <bound method Path.stat of PosixPath('/basepath/some_dir/some_file')>, args = (), kwargs = {}

def assert_raises_os_error(self, subtype, expression, *args, **kwargs):
"""Asserts that a specific subtype of OSError is raised."""
try:
>           expression(*args, **kwargs)

pyfakefs/tests/test_utils.py:87: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/some_dir/some_file')

def stat(self, *, follow_symlinks=True):
"""
Return the result of the stat() system call on this path, like
os.stat() does.
"""
>       return os.stat(self, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/some_dir/some_file'

/usr/lib/python3.11/pathlib.py:1011: FileNotFoundError

During handling of the above exception, another exception occurred:

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibFileObjectPropertyTest testMethod=test_stat_file_in_unreadable_dir>

def test_stat_file_in_unreadable_dir(self):
self.check_posix_only()
dir_path = self.make_path('some_dir')
file_path = self.os.path.join(dir_path, 'some_file')
self.create_file(file_path)
self.os.chmod(dir_path, 0o000)
if not is_root():
>           self.assert_raises_os_error(
errno.EACCES, self.path(file_path).stat)

pyfakefs/tests/fake_pathlib_test.py:435: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyfakefs/tests/test_utils.py:93: in assert_raises_os_error
self.assertEqual(subtype, exc.errno)
E   AssertionError: 13 != 2
_________________________________________________________________ FakePathlibPathFileOperationTest.test_exists _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_exists>

def test_exists(self):
self.skip_if_symlink_not_supported()
self.create_file(self.make_path('home', 'jane', 'test.py'))
self.create_dir(self.make_path('home', 'john'))
self.create_symlink(
self.make_path('john'), self.make_path('home', 'john'))
self.create_symlink(
self.make_path('none'), self.make_path('home', 'none'))

>       self.assertTrue(
self.path(self.make_path('home', 'jane', 'test.py')).exists())
E       AssertionError: False is not true

pyfakefs/tests/fake_pathlib_test.py:502: AssertionError
__________________________________________________________________ FakePathlibPathFileOperationTest.test_glob __________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_glob>

def test_glob(self):
self.create_file(self.make_path('foo', 'setup.py'))
self.create_file(self.make_path('foo', 'all_tests.py'))
self.create_file(self.make_path('foo', 'README.md'))
self.create_file(self.make_path('foo', 'setup.pyc'))
path = self.path(self.make_path('foo'))
>       self.assertEqual(sorted(path.glob('*.py')),
[self.path(self.make_path('foo', 'all_tests.py')),
self.path(self.make_path('foo', 'setup.py'))])
E       AssertionError: Lists differ: [] != [PosixPath('/basepath/foo/all_tests.py'), PosixPath('/basepath/foo/setup.py')]
E       
E       Second list contains 2 additional elements.
E       First extra element 0:
E       PosixPath('/basepath/foo/all_tests.py')
E       
E       - []
E       + [PosixPath('/basepath/foo/all_tests.py'), PosixPath('/basepath/foo/setup.py')]

pyfakefs/tests/fake_pathlib_test.py:728: AssertionError
____________________________________________________________ FakePathlibPathFileOperationTest.test_glob_case_posix _____________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_glob_case_posix>

@unittest.skipIf(is_windows, 'Posix specific test')
def test_glob_case_posix(self):
self.check_posix_only()
self.create_file(self.make_path('foo', 'setup.py'))
self.create_file(self.make_path('foo', 'all_tests.PY'))
self.create_file(self.make_path('foo', 'README.md'))
self.create_file(self.make_path('foo', 'example.Py'))
path = self.path(self.make_path('foo'))
>       self.assertEqual(sorted(path.glob('*.py')),
[self.path(self.make_path('foo', 'setup.py'))])
E       AssertionError: Lists differ: [] != [PosixPath('/basepath/foo/setup.py')]
E       
E       Second list contains 1 additional elements.
E       First extra element 0:
E       PosixPath('/basepath/foo/setup.py')
E       
E       - []
E       + [PosixPath('/basepath/foo/setup.py')]

pyfakefs/tests/fake_pathlib_test.py:752: AssertionError
______________________________________________________________ FakePathlibPathFileOperationTest.test_hardlink_to _______________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_hardlink_to>

@unittest.skipIf(sys.version_info < (3, 10),
'hardlink_to new in Python 3.10')
def test_hardlink_to(self):
self.skip_if_symlink_not_supported()
file_name = self.make_path('foo', 'bar.txt')
self.create_file(file_name)
self.assertEqual(1, self.os.stat(file_name).st_nlink)
link_path = self.path(self.make_path('link_to_bar'))
path = self.path(file_name)
>       link_path.hardlink_to(path)

pyfakefs/tests/fake_pathlib_test.py:667: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/link_to_bar'), target = PosixPath('/basepath/foo/bar.txt')

def hardlink_to(self, target):
"""
Make this path a hard link pointing to the same file as *target*.

Note the order of arguments (self, target) is the reverse of os.link's.
"""
if not hasattr(os, "link"):
raise NotImplementedError("os.link() not available on this system")
>       os.link(target, self)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt' -> '/basepath/link_to_bar'

/usr/lib/python3.11/pathlib.py:1206: FileNotFoundError
________________________________________________________________ FakePathlibPathFileOperationTest.test_iterdir _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_iterdir>

def test_iterdir(self):
self.create_file(self.make_path('foo', 'bar', 'file1'))
self.create_file(self.make_path('foo', 'bar', 'file2'))
self.create_file(self.make_path('foo', 'bar', 'file3'))
path = self.path(self.make_path('foo', 'bar'))
>       contents = [entry for entry in path.iterdir()]

pyfakefs/tests/fake_pathlib_test.py:717: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyfakefs/tests/fake_pathlib_test.py:717: in <listcomp>
contents = [entry for entry in path.iterdir()]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar')

def iterdir(self):
"""Iterate over the files in this directory.  Does not yield any
result for the special paths '.' and '..'.
"""
>       for name in os.listdir(self):
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar'

/usr/lib/python3.11/pathlib.py:929: FileNotFoundError
________________________________________________________________ FakePathlibPathFileOperationTest.test_link_to _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_link_to>

@unittest.skipIf(sys.version_info < (3, 8),
'link_to new in Python 3.8')
def test_link_to(self):
self.skip_if_symlink_not_supported()
file_name = self.make_path('foo', 'bar.txt')
self.create_file(file_name)
self.assertEqual(1, self.os.stat(file_name).st_nlink)
link_name = self.make_path('link_to_bar')
path = self.path(file_name)
>       path.link_to(link_name)

pyfakefs/tests/fake_pathlib_test.py:653: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3.11/pathlib.py:1224: in link_to
self.__class__(target).hardlink_to(self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/link_to_bar'), target = PosixPath('/basepath/foo/bar.txt')

def hardlink_to(self, target):
"""
Make this path a hard link pointing to the same file as *target*.

Note the order of arguments (self, target) is the reverse of os.link's.
"""
if not hasattr(os, "link"):
raise NotImplementedError("os.link() not available on this system")
>       os.link(target, self)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt' -> '/basepath/link_to_bar'

/usr/lib/python3.11/pathlib.py:1206: FileNotFoundError
_________________________________________________________________ FakePathlibPathFileOperationTest.test_mkdir __________________________________________________________________

self = PosixPath('/basepath/foo/bar'), mode = 511, parents = True, exist_ok = False

def mkdir(self, mode=0o777, parents=False, exist_ok=False):
"""
Create a new directory at this given path.
"""
try:
>           os.mkdir(self, mode)
E           FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar'

/usr/lib/python3.11/pathlib.py:1114: FileNotFoundError

During handling of the above exception, another exception occurred:

self = PosixPath('/basepath/foo'), mode = 511, parents = True, exist_ok = True

def mkdir(self, mode=0o777, parents=False, exist_ok=False):
"""
Create a new directory at this given path.
"""
try:
>           os.mkdir(self, mode)
E           FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo'

/usr/lib/python3.11/pathlib.py:1114: FileNotFoundError

During handling of the above exception, another exception occurred:

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_mkdir>

def test_mkdir(self):
dir_name = self.make_path('foo', 'bar')
self.assert_raises_os_error(errno.ENOENT,
self.path(dir_name).mkdir)
>       self.path(dir_name).mkdir(parents=True)

pyfakefs/tests/fake_pathlib_test.py:686: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3.11/pathlib.py:1118: in mkdir
self.parent.mkdir(parents=True, exist_ok=True)
/usr/lib/python3.11/pathlib.py:1118: in mkdir
self.parent.mkdir(parents=True, exist_ok=True)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath'), mode = 511, parents = True, exist_ok = True

def mkdir(self, mode=0o777, parents=False, exist_ok=False):
"""
Create a new directory at this given path.
"""
try:
>           os.mkdir(self, mode)
E           PermissionError: [Errno 13] Permission denied: '/basepath'

/usr/lib/python3.11/pathlib.py:1114: PermissionError
_____________________________________________________________ FakePathlibPathFileOperationTest.test_mkdir_exist_ok _____________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_mkdir_exist_ok>

def test_mkdir_exist_ok(self):
dir_name = self.make_path('foo', 'bar')
self.create_dir(dir_name)
>       self.path(dir_name).mkdir(exist_ok=True)

pyfakefs/tests/fake_pathlib_test.py:694: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar'), mode = 511, parents = False, exist_ok = True

def mkdir(self, mode=0o777, parents=False, exist_ok=False):
"""
Create a new directory at this given path.
"""
try:
>           os.mkdir(self, mode)
E           FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar'

/usr/lib/python3.11/pathlib.py:1114: FileNotFoundError
________________________________________________________________ FakePathlibPathFileOperationTest.test_readlink ________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_readlink>

@unittest.skipIf(sys.version_info < (3, 9),
'readlink new in Python 3.9')
def test_readlink(self):
self.skip_if_symlink_not_supported()
link_path = self.make_path('foo', 'bar', 'baz')
target = self.make_path('tarJAY')
self.create_symlink(link_path, target)
path = self.path(link_path)
>       self.assert_equal_paths(path.readlink(), self.path(target))

pyfakefs/tests/fake_pathlib_test.py:680: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar/baz')

def readlink(self):
"""
Return the path to which the symbolic link points.
"""
if not hasattr(os, "readlink"):
raise NotImplementedError("os.readlink() not available on this system")
>       return self._from_parts((os.readlink(self),))
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar/baz'

/usr/lib/python3.11/pathlib.py:1085: FileNotFoundError
_________________________________________________________________ FakePathlibPathFileOperationTest.test_rename _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_rename>

def test_rename(self):
file_name = self.make_path('foo', 'bar.txt')
self.create_file(file_name, contents='test')
new_file_name = self.make_path('foo', 'baz.txt')
>       self.path(file_name).rename(new_file_name)

pyfakefs/tests/fake_pathlib_test.py:574: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar.txt'), target = '/basepath/foo/baz.txt'

def rename(self, target):
"""
Rename this path to the target path.

The target path may be absolute or relative. Relative paths are
interpreted relative to the current working directory, *not* the
directory of the Path object.

Returns the new Path instance pointing to the target path.
"""
>       os.rename(self, target)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt' -> '/basepath/foo/baz.txt'

/usr/lib/python3.11/pathlib.py:1173: FileNotFoundError
________________________________________________________________ FakePathlibPathFileOperationTest.test_replace _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_replace>

def test_replace(self):
self.create_file(self.make_path('foo', 'bar.txt'), contents='test')
self.create_file(self.make_path('bar', 'old.txt'),
contents='replaced')
>       self.path(self.make_path('bar', 'old.txt')).replace(
self.make_path('foo', 'bar.txt'))

pyfakefs/tests/fake_pathlib_test.py:582: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/bar/old.txt'), target = '/basepath/foo/bar.txt'

def replace(self, target):
"""
Rename this path to the target path, overwriting if that path exists.

The target path may be absolute or relative. Relative paths are
interpreted relative to the current working directory, *not* the
directory of the Path object.

Returns the new Path instance pointing to the target path.
"""
>       os.replace(self, target)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/bar/old.txt' -> '/basepath/foo/bar.txt'

/usr/lib/python3.11/pathlib.py:1186: FileNotFoundError
_________________________________________________________________ FakePathlibPathFileOperationTest.test_rmdir __________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_rmdir>

def test_rmdir(self):
dir_name = self.make_path('foo', 'bar')
self.create_dir(dir_name)
>       self.path(dir_name).rmdir()

pyfakefs/tests/fake_pathlib_test.py:704: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar')

def rmdir(self):
"""
Remove this directory.  The directory must be empty.
"""
>       os.rmdir(self)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar'

/usr/lib/python3.11/pathlib.py:1154: FileNotFoundError
________________________________________________________________ FakePathlibPathFileOperationTest.test_samefile ________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_samefile>

def test_samefile(self):
file_name = self.make_path('foo', 'bar.txt')
self.create_file(file_name)
file_name2 = self.make_path('foo', 'baz.txt')
self.create_file(file_name2)
with self.assertRaises(OSError):
self.path(self.make_path('foo', 'other')).samefile(
self.make_path('foo', 'other.txt'))
path = self.path(file_name)
other_name = self.make_path('foo', 'other.txt')
with self.assertRaises(OSError):
path.samefile(other_name)
with self.assertRaises(OSError):
path.samefile(self.path(other_name))
>       self.assertFalse(path.samefile(file_name2))

pyfakefs/tests/fake_pathlib_test.py:627: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyfakefs/fake_pathlib.py:659: in samefile
st = self.stat()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar.txt')

def stat(self, *, follow_symlinks=True):
"""
Return the result of the stat() system call on this path, like
os.stat() does.
"""
>       return os.stat(self, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt'

/usr/lib/python3.11/pathlib.py:1011: FileNotFoundError
_______________________________________________________________ FakePathlibPathFileOperationTest.test_symlink_to _______________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_symlink_to>

def test_symlink_to(self):
self.skip_if_symlink_not_supported()
file_name = self.make_path('foo', 'bar.txt')
self.create_file(file_name)
link_name = self.make_path('link_to_bar')
path = self.path(link_name)
>       path.symlink_to(file_name)

pyfakefs/tests/fake_pathlib_test.py:640: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/link_to_bar'), target = '/basepath/foo/bar.txt', target_is_directory = False

def symlink_to(self, target, target_is_directory=False):
"""
Make this path a symlink pointing to the target path.
Note the order of arguments (link, target) is the reverse of os.symlink.
"""
if not hasattr(os, "symlink"):
raise NotImplementedError("os.symlink() not available on this system")
>       os.symlink(target, self, target_is_directory)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt' -> '/basepath/link_to_bar'

/usr/lib/python3.11/pathlib.py:1196: FileNotFoundError
_____________________________________________________________ FakePathlibPathFileOperationTest.test_touch_existing _____________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_touch_existing>, subtype = 17
expression = <bound method FakePath.touch of PosixPath('/basepath/foo/bar.txt')>, args = (), kwargs = {'exist_ok': False}

def assert_raises_os_error(self, subtype, expression, *args, **kwargs):
"""Asserts that a specific subtype of OSError is raised."""
try:
>           expression(*args, **kwargs)

pyfakefs/tests/test_utils.py:87: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar.txt'), mode = 438, exist_ok = False

def touch(self, mode=0o666, exist_ok=True):
"""Create a fake file for the path with the given access mode,
if it doesn't exist.

Args:
mode: the file mode for the file if it does not exist
exist_ok: if the file already exists and this is True, nothing
happens, otherwise FileExistError is raised

Raises:
FileExistsError: if the file exists and exits_ok is False.
"""
if self._closed:
self._raise_closed()
if self.exists():
if exist_ok:
self.filesystem.utime(self._path(), times=None)
else:
self.filesystem.raise_os_error(errno.EEXIST, self._path())
else:
fake_file = self.open('w')
fake_file.close()
>           self.chmod(mode)

pyfakefs/fake_pathlib.py:697: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar.txt'), mode = 438

def chmod(self, mode, *, follow_symlinks=True):
"""
Change the permissions of the path, like os.chmod().
"""
>       os.chmod(self, mode, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt'

/usr/lib/python3.11/pathlib.py:1130: FileNotFoundError

During handling of the above exception, another exception occurred:

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_touch_existing>

def test_touch_existing(self):
file_name = self.make_path('foo', 'bar.txt')
self.create_file(file_name, contents='test')
file_path = self.path(file_name)
>       self.assert_raises_os_error(
errno.EEXIST, file_path.touch, exist_ok=False)

pyfakefs/tests/fake_pathlib_test.py:608: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyfakefs/tests/test_utils.py:93: in assert_raises_os_error
self.assertEqual(subtype, exc.errno)
E   AssertionError: 17 != 2
___________________________________________________________ FakePathlibPathFileOperationTest.test_touch_non_existing ___________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_touch_non_existing>

def test_touch_non_existing(self):
self.create_dir(self.make_path('foo'))
file_name = self.make_path('foo', 'bar.txt')
>       self.path(file_name).touch(mode=0o444)

pyfakefs/tests/fake_pathlib_test.py:598: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyfakefs/fake_pathlib.py:697: in touch
self.chmod(mode)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar.txt'), mode = 292

def chmod(self, mode, *, follow_symlinks=True):
"""
Change the permissions of the path, like os.chmod().
"""
>       os.chmod(self, mode, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt'

/usr/lib/python3.11/pathlib.py:1130: FileNotFoundError
_________________________________________________________________ FakePathlibPathFileOperationTest.test_unlink _________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibPathFileOperationTest testMethod=test_unlink>

def test_unlink(self):
file_path = self.make_path('foo', 'bar.txt')
self.create_file(file_path, contents='test')
self.assertTrue(self.os.path.exists(file_path))
>       self.path(file_path).unlink()

pyfakefs/tests/fake_pathlib_test.py:592: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar.txt'), missing_ok = False

def unlink(self, missing_ok=False):
"""
Remove this file or link.
If the path is a directory, use rmdir() instead.
"""
try:
>           os.unlink(self)
E           FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt'

/usr/lib/python3.11/pathlib.py:1145: FileNotFoundError
_________________________________________________________________ FakePathlibUsageInOsFunctionsTest.test_stat __________________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibUsageInOsFunctionsTest testMethod=test_stat>

def test_stat(self):
path = self.make_path('foo', 'bar', 'baz')
self.create_file(path, contents='1234567')
>       self.assertEqual(self.os.stat(path), self.path(path).stat())

pyfakefs/tests/fake_pathlib_test.py:1027: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/bar/baz')

def stat(self, *, follow_symlinks=True):
"""
Return the result of the stat() system call on this path, like
os.stat() does.
"""
>       return os.stat(self, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar/baz'

/usr/lib/python3.11/pathlib.py:1011: FileNotFoundError
_________________________________________________________ FakePathlibUsageInOsFunctionsTest.test_stat_follow_symlinks __________________________________________________________

self = <pyfakefs.tests.fake_pathlib_test.FakePathlibUsageInOsFunctionsTest testMethod=test_stat_follow_symlinks>

@unittest.skipIf(sys.version_info < (3, 10), "New in Python 3.10")
def test_stat_follow_symlinks(self):
self.check_posix_only()
directory = self.make_path('foo')
base_name = 'bar'
file_path = self.path(self.os.path.join(directory, base_name))
link_path = self.path(self.os.path.join(directory, 'link'))
contents = "contents"
self.create_file(file_path, contents=contents)
self.create_symlink(link_path, base_name)
self.assertEqual(len(contents),
>                        link_path.stat(follow_symlinks=True)[stat.ST_SIZE])

pyfakefs/tests/fake_pathlib_test.py:1040: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/basepath/foo/link')

def stat(self, *, follow_symlinks=True):
"""
Return the result of the stat() system call on this path, like
os.stat() does.
"""
>       return os.stat(self, follow_symlinks=follow_symlinks)
E       FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/link'

/usr/lib/python3.11/pathlib.py:1011: FileNotFoundError
=============================================================================== warnings summary ===============================================================================
pyfakefs/tests/fake_filesystem_unittest_test.py::TestPyfakefsUnittest::test_fakepathlib
/tmp/pyfakefs-master/pyfakefs/tests/fake_filesystem_unittest_test.py:151: DeprecationWarning: pathlib.Path.__enter__() is deprecated and scheduled for removal in Python 3.13;Path objects as a context manager is a no-op
with pathlib.Path('/fake_file.txt') as p:

pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_link_to
/tmp/pyfakefs-master/pyfakefs/tests/fake_pathlib_test.py:653: DeprecationWarning: pathlib.Path.link_to() is deprecated and is scheduled for removal in Python 3.12. Use pathlib.Path.hardlink_to() instead.
path.link_to(link_name)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================================================================== short test summary info ============================================================================
FAILED pyfakefs/tests/fake_filesystem_unittest_test.py::AdditionalSkipNamesTest::test_fake_path_does_not_exist3 - AssertionError: True is not false
FAILED pyfakefs/tests/fake_filesystem_unittest_test.py::AdditionalSkipNamesTest::test_fake_path_does_not_exist7 - AssertionError: True is not false
FAILED pyfakefs/tests/fake_filesystem_unittest_test.py::AdditionalSkipNamesModuleTest::test_fake_path_does_not_exist3 - AssertionError: True is not false
FAILED pyfakefs/tests/fake_filesystem_unittest_test.py::AdditionalSkipNamesModuleTest::test_fake_path_does_not_exist7 - AssertionError: True is not false
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_chmod_no_followsymlinks - FileNotFoundError: [Errno 2] No such file or directory: '/basep...
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_exists - AssertionError: False is not true
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_is_dir - AssertionError: False is not true
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_is_file - AssertionError: False is not true
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_is_symlink - AssertionError: False is not true
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_iterdir_in_unreadable_dir - AssertionError: 13 != 2
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_lchmod - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/test.py'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_lstat_posix - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/test.py'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_stat - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/test.py'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibFileObjectPropertyTest::test_stat_file_in_unreadable_dir - AssertionError: 13 != 2
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_exists - AssertionError: False is not true
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_glob - AssertionError: Lists differ: [] != [PosixPath('/basepath/foo/all_tests.py'), Posix...
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_glob_case_posix - AssertionError: Lists differ: [] != [PosixPath('/basepath/foo/setup.py')]
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_hardlink_to - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.t...
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_iterdir - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_link_to - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt' ...
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_mkdir - PermissionError: [Errno 13] Permission denied: '/basepath'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_mkdir_exist_ok - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_readlink - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar/baz'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_rename - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt' -...
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_replace - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/bar/old.txt' ...
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_rmdir - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_samefile - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_symlink_to - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.tx...
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_touch_existing - AssertionError: 17 != 2
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_touch_non_existing - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/fo...
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibPathFileOperationTest::test_unlink - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar.txt'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibUsageInOsFunctionsTest::test_stat - FileNotFoundError: [Errno 2] No such file or directory: '/basepath/foo/bar/baz'
FAILED pyfakefs/tests/fake_pathlib_test.py::FakePathlibUsageInOsFunctionsTest::test_stat_follow_symlinks - FileNotFoundError: [Errno 2] No such file or directory: '/basepath...
=============================================== 33 failed, 1213 passed, 815 skipped, 2 xfailed, 2 xpassed, 2 warnings in 10.02s ================================================

How To Reproduce
Run the tests with python3.11

Your environment
Please run the following and paste the output.

(Gentoo) Linux-5.17.7-gentoo-x86_64-Intel-R-_Core-TM-_i7-10510U_CPU_@_1.80GHz-with-glibc2.35
Python 3.11.0b1 (main, May 11 2022, 10:00:03) [GCC 11.3.0]
pyfakefs 4.6.dev0
@mrbean-bremen
Copy link
Member

Thanks - we haven't yet tried to run tests under 3.11, I will have a look later. These are all pathlib-related tests, and as pyfakefs heavily depends on the real pathlib implementation, it is not unexpected that it breaks with a new Python version.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented May 18, 2022

Ok, for my own reference:
In 3.11, the accessor class in pathlib has been removed, which had wrapped all access to os file system functions. Instead, the os functions are called directly now. As we had re-implemented that accessor to access the fake filesystem, this won't work anymore. In principle we could just rely on patching the os functions, this may even be easier, though we have to check how that plays with a faked OS environment, e.g. testing Windows under Linux and vice verse.
I think that most functionality (except for some handling of skip modules) is probably intact, but the tests have to be rewritten to run with a patched enviroment, so that os will be patched in the tests.

Have to look a bit more into this, maybe I will have a closer look over the weekend.

@mrbean-bremen
Copy link
Member

Confirming that the only part really broken is the usage of skip modules that call pathlib functions, while the normal patching of pathlib works (just the tests have to be adapted).
I'm not sure yet how to fix the skip module problem, so this may take a bit.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue May 30, 2022
- add Python 3.11 to CI tests
- adapt the pathlib tests to work with Python 3.11
- adapt handling of pathlib in unfaked modules:
  need to ensure that the original os module is used,
  as pathlib has removed the accessor layer and now
  directly accesses os
- add target_is_directory argument to symlink (ignored)
- 'U' open mode is no longer allowed in Python 3.11
- closes pytest-dev#677
mrbean-bremen added a commit that referenced this issue May 31, 2022
- add Python 3.11 to CI tests
- adapt the pathlib tests to work with Python 3.11
- adapt handling of pathlib in unfaked modules:
  need to ensure that the original os module is used,
  as pathlib has removed the accessor layer and now
  directly accesses os
- add target_is_directory argument to symlink (ignored)
- 'U' open mode is no longer allowed in Python 3.11
- closes #677
github-actions bot pushed a commit that referenced this issue May 31, 2022
…t the pathlib tests to work with Python 3.11 - adapt handling of pathlib in unfaked modules: need to ensure that the original os module is used, as pathlib has removed the accessor layer and now directly accesses os - add target_is_directory argument to symlink (ignored) - 'U' open mode is no longer allowed in Python 3.11 - closes #677
@mrbean-bremen
Copy link
Member

@AndrewAmmerlaan - it should be fixed in master now. I would appreciate if you could test this version - there may be more problems (or regressions from the fix) under Python 3.11 that don't show up in the tests.

@AndrewAmmerlaan
Copy link
Author

@AndrewAmmerlaan - it should be fixed in master now. I would appreciate if you could test this version - there may be more problems (or regressions from the fix) under Python 3.11 that don't show up in the tests.

Great, thanks for looking into it. We currently have two direct dependencies of pyfakefs with python3.11 in Gentoo, I ran both their tests and the pyfakefs tests and found no failures. I'll let you know if I find any additional problems later.

@mrbean-bremen
Copy link
Member

Thanks - good to have some real life tests before making a release!

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