def open(self, mode="r", ensure=False, encoding=None):
        """Return an opened file with the given mode.

        If ensure is True, create parent directories if needed.
        """
        if ensure:
            self.dirpath().ensure(dir=1)
        if encoding:
            return error.checked_call(
                io.open,
                self.strpath,
                mode,
                encoding=encoding,
            )
        return error.checked_call(open, self.strpath, mode)
Return an opened file with the given mode.

        If ensure is True, create parent directories if needed.
        
src/_pytest/_py/path.py