pytest-dev / pytest-dev/pyfakefs
Windows drive-relative pathlib.Path.resolve(strict=False) resolves incorrectly in pyfakefs 6.2.0
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 750
- Forks
- 99
- Avg merge
- 19h 6m
- Merged PRs (30d)
- 6
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Patcher reproduction on Windows and compare pathlib.Path.resolve(strict=False) under pyfakefs 6.2.0 with CPython outside pyfakefs. Done means the drive-relative path resolves to C:\test\test\test_data\dummy1.xml without dropping the first character.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100