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

Method ensure

src/_pytest/_py/path.py:947–959  ·  src/_pytest/_py/path.py::LocalPath.ensure

Ensure that an args-joined path exists (by default as a file). if you specify a keyword argument 'dir=True' then the path is forced to be a directory path.

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

945 return self
946
947 def ensure(self, *args, **kwargs):
948 class="st">"""Ensure that an args-joined path exists (by default as
949 a file). if you specify a keyword argument &class="cm">#x27;dir=True'
950 then the path is forced to be a directory path.
951 class="st">"""
952 p = self.join(*args)
953 if kwargs.get(class="st">"dir", 0):
954 return p._ensuredirs()
955 else:
956 p.dirpath()._ensuredirs()
957 if not p.check(file=1):
958 p.open(class="st">"wb").close()
959 return p
960
961 @overload
962 def stat(self, raising: Literal[True] = ...) -> Stat: ...

Callers 15

ensure_dirMethod · 0.95
openMethod · 0.80
copyMethod · 0.80
write_binaryMethod · 0.80
write_textMethod · 0.80
writeMethod · 0.80
test_remove_fileMethod · 0.80
setuptestfsFunction · 0.80

Calls 7

joinMethod · 0.95
_ensuredirsMethod · 0.80
dirpathMethod · 0.80
openMethod · 0.80
getMethod · 0.45
checkMethod · 0.45
closeMethod · 0.45