Describe the bug
On Windows, pathlib.Path.resolve(strict=False) resolves drive-relative paths incorrectly when pyfakefs is active.
A Windows path like c:test\test_data\dummy1.xml is drive-relative, not absolute. With the current directory set to C:\test, CPython's real pathlib resolves it to:
C:\test\test\test_data\dummy1.xml
With pyfakefs 6.2.0 active, the same path resolves to:
c:\est\test_data\dummy1.xml
The first character of the relative path component (t in test) appears to be dropped, and the path is treated like it starts at the drive root.
This looks like a regression from pyfakefs 6.1.4 to 6.2.0. The same test passed with pyfakefs 6.1.4 and fails with pyfakefs 6.2.0.
How To Reproduce
Please run this on Windows:
from pathlib import Path
import os
from pyfakefs.fake_filesystem_unittest import Patcher
with Patcher() as patcher:
fs = patcher.fs
root = Path("/test")
fs.create_file(root / "test_data" / "dummy1.xml")
os.chdir(root)
drive = Path.cwd().drive
path = Path(f"{drive.lower()}test\\test_data/dummy1.xml")
resolved = path.resolve(strict=False)
print("cwd:", Path.cwd())
print("path:", path)
print("resolved:", resolved)
assert str(resolved) == r"C:\test\test\test_data\dummy1.xml"
Actual output with pyfakefs 6.2.0:
cwd: C:\test
path: c:test\test_data\dummy1.xml
resolved: c:\est\test_data\dummy1.xml
Expected output:
cwd: C:\test
path: c:test\test_data\dummy1.xml
resolved: C:\test\test\test_data\dummy1.xml
For comparison, outside pyfakefs, Path.resolve(strict=False) resolves the drive-relative path relative to the current directory on that drive as expected.
Your environment
Output from the affected environment:
platform: Windows
Python: 3.12.12
pyfakefs: 6.2.0
pytest: 9.0.3
Describe the bug
On Windows,
pathlib.Path.resolve(strict=False)resolves drive-relative paths incorrectly when pyfakefs is active.A Windows path like
c:test\test_data\dummy1.xmlis drive-relative, not absolute. With the current directory set toC:\test, CPython's realpathlibresolves it to:With pyfakefs 6.2.0 active, the same path resolves to:
The first character of the relative path component (
tintest) appears to be dropped, and the path is treated like it starts at the drive root.This looks like a regression from pyfakefs 6.1.4 to 6.2.0. The same test passed with pyfakefs 6.1.4 and fails with pyfakefs 6.2.0.
How To Reproduce
Please run this on Windows:
Actual output with pyfakefs 6.2.0:
Expected output:
For comparison, outside pyfakefs,
Path.resolve(strict=False)resolves the drive-relative path relative to the current directory on that drive as expected.Your environment
Output from the affected environment: