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

Function subst_path_windows

testing/test_link_resolve.py:16–36  ·  view source on GitHub ↗
(filepath: Path)

Source from the content-addressed store, hash-verified

14
15@contextmanager
16def subst_path_windows(filepath: Path):
17 for c in ascii_lowercase[7:]: # Create a subst drive from H-Z.
18 c += ":"
19 if not os.path.exists(c):
20 drive = c
21 break
22 else:
23 raise AssertionError("Unable to find suitable drive letter for subst.")
24
25 directory = filepath.parent
26 basename = filepath.name
27
28 args = ["subst", drive, str(directory)]
29 subprocess.check_call(args)
30 assert os.path.exists(drive)
31 try:
32 filename = Path(drive, os.sep, basename)
33 yield filename
34 finally:
35 args = ["subst", "/D", drive]
36 subprocess.check_call(args)
37
38
39@contextmanager

Callers

nothing calls this directly

Calls 1

existsMethod · 0.45

Tested by

no test coverage detected