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

Function try_makedirs

src/_pytest/assertion/rewrite.py:1157–1179  ·  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

1155
1156
1157def try_makedirs(cache_dir: Path) -> bool:
1158 """Attempt to create the given directory and sub-directories exist.
1159
1160 Returns True if successful or if it already exists.
1161 """
1162 try:
1163 os.makedirs(cache_dir, exist_ok=True)
1164 except (FileNotFoundError, NotADirectoryError, FileExistsError):
1165 # One of the path components was not a directory:
1166 # - we're in a zip file
1167 # - it is a file
1168 return False
1169 except PermissionError:
1170 return False
1171 except OSError as e:
1172 # as of now, EROFS doesn't have an equivalent OSError-subclass
1173 #
1174 # squashfuse_ll returns ENOSYS "OSError: [Errno 38] Function not
1175 # implemented" for a read-only error
1176 if e.errno in {errno.EROFS, errno.ENOSYS}:
1177 return False
1178 raise
1179 return True
1180
1181
1182def 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