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

Method write

src/_pytest/_py/path.py:910–929  ·  src/_pytest/_py/path.py::LocalPath.write

Write data into path. If ensure is True create missing parent directories.

(self, data, mode="w", ensure=False)

Source from the content-addressed store, hash-verified

908 f.write(data)
909
910 def write(self, data, mode=class="st">"w", ensure=False):
911 class="st">"""Write data into path. If ensure is True create
912 missing parent directories.
913 class="st">"""
914 if ensure:
915 self.dirpath().ensure(dir=1)
916 if class="st">"b" in mode:
917 if not isinstance(data, bytes):
918 raise ValueError(class="st">"can only process bytes")
919 else:
920 if not isinstance(data, str):
921 if not isinstance(data, bytes):
922 data = str(data)
923 else:
924 data = data.decode(sys.getdefaultencoding())
925 f = self.open(mode)
926 try:
927 f.write(data)
928 finally:
929 f.close()
930
931 def _ensuredirs(self):
932 parent = self.dirpath()

Callers 15

pytest_sessionfinishMethod · 0.45
tee_writeFunction · 0.45
emitMethod · 0.45
create_cleanup_lockFunction · 0.45
runpytest_inprocessMethod · 0.45
popenMethod · 0.45
setMethod · 0.45
show_test_itemFunction · 0.45
pytest_cmdline_parseFunction · 0.45
unset_tracingFunction · 0.45
show_version_verboseFunction · 0.45

Calls 4

dirpathMethod · 0.95
openMethod · 0.95
ensureMethod · 0.80
closeMethod · 0.45

Tested by 3

runpytest_inprocessMethod · 0.36
popenMethod · 0.36