Temporary file with specific file extension in Python 3
<p>I am writing some unit tests for a piece of code that takes a path and attempts to load the file if it has a known extension, then does more careful checking.</p>

<p>In the unit test, I would like to create a temporary file that has the correct extension, but incorrect contents, in my case an empty file posing as <code>test.tif</code>.</p>

<p>How can I create a temporary file while specifying the extension (or the entire name), using the <code>tempfile</code> module?</p>

<p>I have looked at the <code>NamedTemporaryFile</code> class, as well as the <code>suffix</code> and <code>prefix</code> parameters, but I still cannot set the extension. I suppose I could manually create a file in a temporary directory, but then I loose the self-deleting capability that I am after.</p>