def write_text(self, data, encoding, ensure=False):
        """Write text data into path using the specified encoding.
        If ensure is True create missing parent directories.
        """
        if ensure:
            self.dirpath().ensure(dir=1)
        with self.open("w", encoding=encoding) as f:
            f.write(data)
Write text data into path using the specified encoding.
        If ensure is True create missing parent directories.
        
src/_pytest/_py/path.py