Skip to content

Fix #11603 follow-up: Correct make_numbered_dir multiprocess-safety docstring - #15542

Open
ARUNAGIRINATHAN-K wants to merge 3 commits into
pytest-dev:mainfrom
ARUNAGIRINATHAN-K:flaky-hunter/fix-11603-docstring-multiprocess-safe
Open

ARUNAGIRINATHAN-K wants to merge 3 commits into
pytest-dev:mainfrom
ARUNAGIRINATHAN-K:flaky-hunter/fix-11603-docstring-multiprocess-safe

Conversation

@ARUNAGIRINATHAN-K

Copy link
Copy Markdown

Follow-up to #11603 / #11611

Investigation: Ran test_make_numbered_dir_multiprocess_safe 20/20 isolated
Windows runs with --runxfail on pytest 10.0.0.dev108+gf0b067d19 / Python 3.13.14.
All passed. With normal marker, test reports XPASS.

That does not invalidate the Fedora CI failures in #11603 (1-2/10 builds).
20 Windows runs do not prove the race is absent — conditions differ
(no pytest-xdist, different scheduler / FS).

What remains is a documentation inconsistency:

src/_pytest/_py/path.py:1275 — py.path.local.make_numbered_dir
docstring still describes the locked algorithm as multiprocess-safe,
contrary to the upstream finding in #11611:

  1. Allocation/pruning race: scan max -> create next number -> another
    process creates it first -> retry can raise EEXIST
  2. Lifetime race: directory can be removed between allocation and write
    -> ENOENT

This PR does NOT change behavior. It corrects the docstring to state
that the legacy implementation is NOT guaranteed multiprocess-safe,
and points users to pytest's pathlib.make_numbered_dir_with_cleanup
(src/_pytest/pathlib.py:481, used via tmpdir.py:265) for pytest's
own temp-dir flow.

No source files modified in investigation. No new defect claimed.

What To Actually Change

In src/_pytest/_py/path.py around line 1275:

# Before
"""
Make a numbered directory, using lock files to make it multiprocess-safe.
...
"""

# After
"""
Make a numbered directory.

.. note::
    This legacy ``py.path.local`` implementation is NOT guaranteed to be
    multiprocess-safe, even with lock files. See pytest issue #11603 and
    PR #11611: concurrent allocation/pruning can raise ``EEXIST``, and
    concurrent cleanup can raise ``ENOENT`` between allocation and use.

    Pytest's own temporary-directory code does not use this method; it
    uses :func:`_pytest.pathlib.make_numbered_dir_with_cleanup`.
"""

…s-safety docstring

Legacy py.path.local.make_numbered_dir is not guaranteed
multiprocess-safe per pytest-dev#11611, even with lock files. Update
docstring to reflect that and point to
_pytest.pathlib.make_numbered_dir_with_cleanup used by pytest core.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant