MCPcopy Create free account
hub / github.com/pytest-dev/pytest / make_numbered_dir

Function make_numbered_dir

src/_pytest/pathlib.py:209–227  ·  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

207
208
209def make_numbered_dir(root: Path, prefix: str, mode: int = 0o700) -> Path:
210 """Create a directory with an increased number as suffix for the given prefix."""
211 for i in range(10):
212 # try up to 10 times to create the folder
213 max_existing = max(map(parse_num, find_suffixes(root, prefix)), default=-1)
214 new_number = max_existing + 1
215 new_path = root.joinpath(f"{prefix}{new_number}")
216 try:
217 new_path.mkdir(mode=mode)
218 except Exception:
219 pass
220 else:
221 _force_symlink(root, prefix + "current", new_path)
222 return new_path
223 else:
224 raise OSError(
225 "could not create numbered dir with prefix "
226 "{prefix} in {root} after 10 tries".format(prefix=prefix, root=root)
227 )
228
229
230def 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 4

find_suffixesFunction · 0.85
_force_symlinkFunction · 0.85
mkdirMethod · 0.45
formatMethod · 0.45

Tested by 5

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