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

Fake pathlib not working with Python 3.12-dev #770

Closed
mrbean-bremen opened this issue Jan 17, 2023 · 4 comments · Fixed by #798
Closed

Fake pathlib not working with Python 3.12-dev #770

mrbean-bremen opened this issue Jan 17, 2023 · 4 comments · Fixed by #798

Comments

@mrbean-bremen
Copy link
Member

With the latest Python 3.12 version the CI tests for this version fail with the traceback:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\a\pyfakefs\pyfakefs\pyfakefs\tests\all_tests_without_extra_packages.py", line 30, in <module>
    from pyfakefs.tests.all_tests import AllTests  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\a\pyfakefs\pyfakefs\pyfakefs\tests\all_tests.py", line 21, in <module>
    from pyfakefs.tests import (
  File "D:\a\pyfakefs\pyfakefs\pyfakefs\tests\dynamic_patch_test.py", line 19, in <module>
    from pyfakefs import fake_filesystem_unittest
  File "D:\a\pyfakefs\pyfakefs\pyfakefs\fake_filesystem_unittest.py", line 90, in <module>
    from pyfakefs import fake_pathlib
  File "D:\a\pyfakefs\pyfakefs\pyfakefs\fake_pathlib.py", line 181, in <module>
    flavour = pathlib._Flavour  # type: ignore [attr-defined]
              ^^^^^^^^^^^^^^^^
AttributeError: module 'pathlib' has no attribute '_Flavour'

Looks like the pathlib implementation has changed again (it already did change substantially in 3.11). The fake pathlib has to be adapted accordingly.

@mrbean-bremen
Copy link
Member Author

We don't support 3.12 yet, so this is not a bug.

@browniebroke
Copy link
Contributor

browniebroke commented Jan 17, 2023

More context on the change (I think): python/cpython#31691

@mrbean-bremen
Copy link
Member Author

mrbean-bremen commented Jan 17, 2023

@browniebroke - thanks! That looks like a sensible change, given that pyfakefs also subclasses these classes and had to go through some hoops to make it work. Should not be too big a deal to adapt... Looks like a bit more work - disabled 3.12 tests until I get to this.

mrbean-bremen added a commit that referenced this issue Jan 17, 2023
- pathlib implementation has changed, fake pathlib
  has to be adapted first
  (see #770)
@mrbean-bremen
Copy link
Member Author

Apart from the changed pathlib (which I'm on the track of getting to work), there is also a change in os.path under Windows, that now uses some OS-specific functions for isdir, isfile, islink and exists (called _path_isdir, _path_isfile etc.), which breaks patching these functions and currently fail some tests.
There is a also new function os.path.splitroot which has to be handled (apart from isjunction which already has some minimal implementation) in 3.12.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Mar 29, 2023
- adapt for changed pathlib implementation (removed flavour implementation)
- Windows: add patching for some os.path functions now implemented in nt instead of ntpath
- fix handling of devnull for changed OS
- add fake implementation for os.path.splitroot
- fixes pytest-dev#770
mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Mar 30, 2023
- adapt for changed pathlib implementation (removed flavour implementation)
- Windows: add patching for some os.path functions now implemented in nt instead of ntpath
- fix handling of devnull for changed OS
- add fake implementation for os.path.splitroot
- fixes pytest-dev#770
mrbean-bremen added a commit that referenced this issue Mar 30, 2023
- adapt for changed pathlib implementation (removed flavour implementation)
- Windows: add patching for some os.path functions now implemented in nt instead of ntpath
- fix handling of devnull for changed OS
- add fake implementation for os.path.splitroot
- fixes #770
@bazaah bazaah mentioned this issue May 20, 2024
14 tasks
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