Repository navigation
tests: run the CPython pathlib test suites of the newest patch releases on all supported Pythons - #609
Merged
Conversation
ap--
force-pushed
the
tests-pathlib-suites
branch
from
December 5, 2026 22:34
d0dff5e to
ba7b1eb
Compare
Vendor CPython's Lib/test/test_pathlib/test_pathlib.py for the newer Python versions, so that CPython's own pathlib tests run against the local UPath classes on every supported Python version: - test_pathlib_313.py from v3.13.16 (cbc944f4bc59) - test_pathlib_314.py from v3.14.8 (8e6e75d9102e) - test_pathlib_315.py from v3.15.0 (d220409a13b7) These are the latest patch releases uv provides. On 3.13 the test classes inherit from mixins in test_pathlib_abc.py, so only the DummyPurePathTest and DummyPathTest mixins are vendored, as _test_pathlib_abc_313.py. The pathlib._abc protocol tests are left out. conftest.py records the source commits, and collects each file only on its own Python version. _test_support.py gets the missing helpers from CPython's test.support at v3.15.0. The files are adapted like the 3.12 suite. The concrete test classes run against UPath, PosixUPath, WindowsUPath and a registered subclass, and the pure path tests only run as mixins of these classes. Tests that only cover the standard library (lazy imports, PurePath subclasses, CompatiblePathTest) are dropped. The needs_posix and needs_windows checks use the parser of an instance, because the parser of UPath depends on the protocol. Intentional UPath deviations are marked xfail with a reason, or the assertion is relaxed: UPath.from_uri() returns a FilePath, keyword arguments are storage_options, UPath has no private _parse_path(), direct UPath subclasses aren't pathlib.Path subclasses, UPath adds attributes to the pathlib API, and some overrides lack pathlib's docstrings. One candidate bug is marked xfail(strict=False) on 3.14 and 3.15: PosixUPath.copy(..., preserve_metadata=True) doesn't preserve the metadata, because LocalPath._copy_from = UPath._copy_from drops the preserve_metadata argument.
Re-vendor Lib/test/test_pathlib.py from the newest patch releases: - test_pathlib_311.py from v3.11.18 (26badd80b6dc) - test_pathlib_312.py from v3.12.16 (2c2462afc5d9) The existing UPath adaptations were ported onto the new files. On 3.12 the extra relative_to() checks are upstream now, and the commented out with_name()/with_stem() checks are restored, because upstream changed them to match the current pathlib behaviour. EnvironmentVarGuard.unset() in _test_support.py now accepts several variables, as in CPython. The Windows-only expanduser tests of the newer suites need this. No new xfails.
ap--
force-pushed
the
tests-pathlib-suites
branch
from
December 5, 2026 22:56
0165870 to
b5b5703
Compare
ap--
marked this pull request as ready for review
December 5, 2026 23:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #608.
Until now, CPython's own pathlib tests only ran against
PosixUPath/WindowsUPath/UPathon Python 3.11 and 3.12, and the 3.12 suite came from 3.12.0b4. This vendors CPython'stest_pathlib.pyfor the other supported versions, and updates the 3.11 and 3.12 suites to the newest patch releases:test_pathlib_311.py26badd80b6dc), was846a23d0b8f0test_pathlib_312.py2c2462afc5d9), was 3.12.0b4 (97a6a418167f)test_pathlib_313.pycbc944f4bc59)test_pathlib_314.py8e6e75d9102e)test_pathlib_315.pyd220409a13b7)(Linux; most skips are Windows-only tests.) For 3.13–3.15, the test files are identical in the newest patch releases (v3.13.18, v3.14.10, v3.15.2).
test_pathlib_abc.py. Only theDummyPurePathTestandDummyPathTestmixins are vendored, as_test_pathlib_abc_313.py, without thepathlib._abcprotocol tests. That file is excluded from black, flake8 and pre-commit like the other vendored files.conftest.pyrecords the source commit and path of each file, and collects each file only on its own Python version._test_support.pygets the missing helpers from CPython'stest.supportat v3.15.0.UPath,PosixUPath,WindowsUPathand a registered subclass. Tests that only cover the standard library (lazy imports,PurePathsubclasses,CompatiblePathTest) are dropped.relative_to()checks the old file added by hand are now part of upstream. Thewith_name('.')/with_stem('.')checks and the Windows'd:'checks are active again, because they pass now.EnvironmentVarGuard.unset()accepts several names like in CPython, which the Windows-onlytest_expanduserof 3.13–3.15 needs.needs_posix/needs_windowschecks use the parser of an instance, because the parser ofUPathdepends on the protocol.PathSubclassTestregisters its class withenterContext(), which avoids a flaky failure whensetUp()skips.xfails
Intentional UPath deviations:
UPath.from_uri()returns aFilePathforfile:URIsstorage_options(test_passing_kwargs_*)UPathhas no private_parse_path()UPathsubclasses are fsspec based, notpathlib.PathsubclassesCandidate bug, marked
xfail(strict=False)on 3.14 and 3.15:PosixUPath.copy(target, preserve_metadata=True)doesn't preserve the file mode and timestamps, becauseLocalPath._copy_from = UPath._copy_fromdrops thepreserve_metadataargument. Reproduced on 3.15:pathlib.Pathkeeps mode0o640and the mtime,PosixUPathdoesn't. The same goes for the mode of copied symlinks, on platforms withos.lchmod(macOS CI):test_copy_link_preserve_metadatais xfailed there. To be fixed in a separate PR.Not verified locally
The Windows and macOS code paths (
WindowsUPath, and the UPath-on-Windows xfails). CI covers them.