MCPcopy
hub / github.com/pytest-dev/pytest / make_numbered_dir

Function make_numbered_dir

src/_pytest/pathlib.py:224–242  ·  view source on GitHub ↗

Create a directory with an increased number as suffix for the given prefix.

(root: Path, prefix: str, mode: int = 0o700)

Source from the content-addressed store, hash-verified

222
223
224def make_numbered_dir(root: Path, prefix: str, mode: int = 0o700) -> Path:
225 """Create a directory with an increased number as suffix for the given prefix."""
226 for i in range(10):
227 # try up to 10 times to create the directory
228 max_existing = max(map(parse_num, find_suffixes(root, prefix)), default=-1)
229 new_number = max_existing + 1
230 new_path = root.joinpath(f"{prefix}{new_number}")
231 try:
232 new_path.mkdir(mode=mode)
233 except Exception:
234 pass
235 else:
236 _force_symlink(root, prefix + "current", new_path)
237 return new_path
238 else:
239 raise OSError(
240 "could not create numbered dir with prefix "
241 f"{prefix} in {root} after 10 tries"
242 )
243
244
245def create_cleanup_lock(p: Path) -> Path:

Callers 7

runpytest_subprocessMethod · 0.90
test_pyc_vs_pyoMethod · 0.90
test_makeMethod · 0.90
test_cleanup_lockedMethod · 0.90
mktempMethod · 0.85

Calls 3

find_suffixesFunction · 0.85
_force_symlinkFunction · 0.85
mkdirMethod · 0.45

Tested by 5

runpytest_subprocessMethod · 0.72
test_pyc_vs_pyoMethod · 0.72
test_makeMethod · 0.72
test_cleanup_lockedMethod · 0.72