Skip to content

tests: run the CPython pathlib test suites of the newest patch releases on all supported Pythons - #609

Merged
ap-- merged 2 commits into
fsspec:mainfrom
ap--:tests-pathlib-suites
Dec 5, 2026
Merged

ap-- merged 2 commits into
fsspec:mainfrom
ap--:tests-pathlib-suites

Conversation

@ap--

@ap-- ap-- commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #608.

Until now, CPython's own pathlib tests only ran against PosixUPath/WindowsUPath/UPath on Python 3.11 and 3.12, and the 3.12 suite came from 3.12.0b4. This vendors CPython's test_pathlib.py for the other supported versions, and updates the 3.11 and 3.12 suites to the newest patch releases:

file CPython passed skipped xfailed
test_pathlib_311.py v3.11.18 (26badd80b6dc), was 846a23d0b8f0 188 135 0
test_pathlib_312.py v3.12.16 (2c2462afc5d9), was 3.12.0b4 (97a6a418167f) 280 148 0
test_pathlib_313.py v3.13.16 (cbc944f4bc59) 494 340 9
test_pathlib_314.py v3.14.8 (8e6e75d9102e) 549 331 17
test_pathlib_315.py v3.15.0 (d220409a13b7) 561 335 17

(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).

  • On 3.13 the test classes inherit from mixins in test_pathlib_abc.py. Only the DummyPurePathTest and DummyPathTest mixins are vendored, as _test_pathlib_abc_313.py, without the pathlib._abc protocol tests. That file is excluded from black, flake8 and pre-commit like the other vendored files.
  • conftest.py records the source commit and path of each file, 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 adaptations follow the 3.12 suite and are small (171–189 changed lines per file). The concrete test classes run against UPath, PosixUPath, WindowsUPath and a registered subclass. Tests that only cover the standard library (lazy imports, PurePath subclasses, CompatiblePathTest) are dropped.
  • 3.11 and 3.12 (second commit): the existing adaptations were ported to the new upstream files. In 3.12, the relative_to() checks the old file added by hand are now part of upstream. The with_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-only test_expanduser of 3.13–3.15 needs.
  • The needs_posix/needs_windows checks use the parser of an instance, because the parser of UPath depends on the protocol. PathSubclassTest registers its class with enterContext(), which avoids a flaky failure when setUp() skips.

xfails

Intentional UPath deviations:

  • UPath.from_uri() returns a FilePath for file: URIs
  • keyword arguments are storage_options (test_passing_kwargs_*)
  • UPath has no private _parse_path()
  • direct UPath subclasses are fsspec based, not pathlib.Path subclasses
  • some overrides don't carry pathlib's docstrings
  • on 3.13, the API check accepts UPath's additional attributes

Candidate 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, because LocalPath._copy_from = UPath._copy_from drops the preserve_metadata argument. Reproduced on 3.15: pathlib.Path keeps mode 0o640 and the mtime, PosixUPath doesn't. The same goes for the mode of copied symlinks, on platforms with os.lchmod (macOS CI): test_copy_link_preserve_metadata is 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.

@ap--
ap-- force-pushed the tests-pathlib-suites branch from d0dff5e to ba7b1eb Compare December 5, 2026 22:34
@ap-- ap-- changed the title tests: run the CPython pathlib test suites on Python 3.13, 3.14 and 3.15 tests: run the CPython pathlib test suites of the newest patch releases on all supported Pythons Dec 5, 2026
ap-- added 2 commits December 5, 2026 23:56
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--
ap-- force-pushed the tests-pathlib-suites branch from 0165870 to b5b5703 Compare December 5, 2026 22:56
@ap--
ap-- marked this pull request as ready for review December 5, 2026 23:07
@ap--
ap-- merged commit 1730a26 into fsspec:main Dec 5, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant