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

Function try_makedirs

src/_pytest/assertion/rewrite.py:1101–1120  ·  view source on GitHub ↗

Attempt to create the given directory and sub-directories exist. Returns True if successful or if it already exists.

(cache_dir: Path)

Source from the content-addressed store, hash-verified

1099
1100
1101def try_makedirs(cache_dir: Path) -> bool:
1102 """Attempt to create the given directory and sub-directories exist.
1103
1104 Returns True if successful or if it already exists.
1105 """
1106 try:
1107 os.makedirs(cache_dir, exist_ok=True)
1108 except (FileNotFoundError, NotADirectoryError, FileExistsError):
1109 # One of the path components was not a directory:
1110 # - we're in a zip file
1111 # - it is a file
1112 return False
1113 except PermissionError:
1114 return False
1115 except OSError as e:
1116 # as of now, EROFS doesn't have an equivalent OSError-subclass
1117 if e.errno == errno.EROFS:
1118 return False
1119 raise
1120 return True
1121
1122
1123def get_cache_dir(file_path: Path) -> Path:

Callers 2

test_try_makedirsFunction · 0.90
exec_moduleMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_try_makedirsFunction · 0.72