def METHOD_NAME(self, name, ext, contents=None):
    temp = tempfile.NamedTemporaryFile(
        dir=self.tempdir,
        suffix=ext,
        prefix=name + '.',
        delete=False,
    )
    if contents:
        with open(temp.name, 'w') as f:
            f.write(contents)
    return temp.name