This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jdufresne
Recipients jdufresne
Date 2016-12-04.17:47:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1480873647.39.0.877280517926.issue28867@psf.upfronthosting.co.za>
In-reply-to
Content
When using unittest, I'll frequently enable -Wall to help catch code smells and potential bugs.

One feature of this, I'm told when files aren't explicitly closed with an error like: "ResourceWarning: unclosed file <...>". I've noticed this warning is generated for an unclosed tempfile.TemporaryFile (good), but not for an unclosed tempfile.NamedTemporaryFile (possible bug).

I've verified this on Python 3.5 and 3.6.

Example test:

```
import tempfile
import unittest


class MyTest(unittest.TestCase):
    def test_temporary_file(self):
        tempfile.TemporaryFile()

    def test_named_temporary_file(self):
        tempfile.NamedTemporaryFile()
```

Actual output:

```
$ Python-3.6.0b4/python --version
Python 3.6.0b4
$ Python-3.6.0b4/python -Wall -m unittest -v test
test_named_temporary_file (test.MyTest) ... ok
test_temporary_file (test.MyTest) ... /home/jon/test.py:7: ResourceWarning: unclosed file <_io.BufferedRandom name=3>
  tempfile.TemporaryFile()
ok

----------------------------------------------------------------------
Ran 2 tests in 0.004s

OK

```

Expected:

I expect both tests to generate a ResourceWarning, as neither test explicitly closes the file.
History
Date User Action Args
2016-12-04 17:47:27jdufresnesetrecipients: + jdufresne
2016-12-04 17:47:27jdufresnesetmessageid: <1480873647.39.0.877280517926.issue28867@psf.upfronthosting.co.za>
2016-12-04 17:47:27jdufresnelinkissue28867 messages
2016-12-04 17:47:27jdufresnecreate