Message282352
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. |
|
Date |
User |
Action |
Args |
2016-12-04 17:47:27 | jdufresne | set | recipients:
+ jdufresne |
2016-12-04 17:47:27 | jdufresne | set | messageid: <1480873647.39.0.877280517926.issue28867@psf.upfronthosting.co.za> |
2016-12-04 17:47:27 | jdufresne | link | issue28867 messages |
2016-12-04 17:47:27 | jdufresne | create | |
|