Repository navigation
fix: handle curdir tail in makedirs like the real os - #1371
Merged
mrbean-bremen merged 2 commits intoNov 10, 2026
Merged
Conversation
os.makedirs("foo/bar/.") on a fresh path created foo/bar and then
raised FileExistsError, because the curdir special case copied from
os.py compared the tail against self.filesystem.cwd instead of the
"." literal. With cwd usually being "/" the comparison never
matched, the early return was skipped, and the final mkdir hit the
just-created directory.
Compare against "." (curdir), matching os.py, so a freshly created
path with a /. tail returns cleanly. An already-existing path with a
/. tail keeps raising EEXIST (or passing with exist_ok=True), the
same as the real os.
Fixes pytest-dev#1370
Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
| directory with a path ending in `/.` (e.g. `os.makedirs("foo/bar/.")`), | ||
| because the curdir special case compared the tail against the current | ||
| working directory instead of `"."` | ||
| (see [issue #1370](https://github.com/pytest-dev/pyfakefs/issues/1370)) |
Member
There was a problem hiding this comment.
Please make this shorter - no need to re-iterate the reason for the issue here (e.g. just skip the "because..." part)
Contributor
Author
There was a problem hiding this comment.
Done in d2cba47 — dropped the "because..." sentence, the entry is now just the fix and the issue link.
mrbean-bremen
approved these changes
Nov 10, 2026
Contributor
Author
|
Thanks for the merge on #1371 ("fix: handle curdir tail in makedirs like the real os"). I'm also exploring my next role right now (Full Stack (PHP, NodeJs, Python) / Data Science / Applied AI / Devtools, based in India) — if you or your network is hiring, I'd love an intro: |
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.
os.makedirs("foo/bar/.")on a fresh path raisedFileExistsErrorunder the fake filesystem, while the realoscreatesfoo/barand returns.The curdir special case in
FakeOsModule.makedirs— copied fromos.py— compares the path tail againstself.filesystem.cwdinstead of the"."literal. With cwd usually being"/", thetail == cdircheck never matches, the early return is skipped, and the finalmkdirhits the directory the recursion just created:Real behavior (checked on CPython 3.13, Linux): a fresh path with a
/.tail creates the directory and returns; an already-existing path with a/.tail raisesEEXIST(or passes withexist_ok=True). This change restores exactly that by comparing against".", and keeps everything else untouched.Fixes #1370.
Verification (system Python 3.13 on a headless host, no installable deps):
pyfakefs/tests/fake_os_test.py(fresh/.tail, existing/.tail raisesEEXISTthen passes withexist_ok=True, relative./form, bytes path): 3 fail onmain@f693c54, all pass with this change. These tests run against both the fake and the real filesystem (theFakeOsModuleTestbase), so the parity is pinned both ways.fake_os_test.py: 556 passed / 553 skipped (Windows-only skips) with the fix.fake_filesystem_test.py(295),fake_pathlib_test.py(195),fake_filesystem_vs_real_test.py(28),fake_filesystem_shutil_test.py(36).fake_filesystem_unittest_test.pycannot complete on this host (OOM at ~67% of the module, identical on unpatchedmain— pre-existing host RAM limitation, not caused by this change).