Message210377
Given the following file test_reswarn.py:
====
import unittest
class TestResourceWarning(unittest.TestCase):
def test_it(self):
self.assertIn("TestResourceWarning", open(__file__).read())
====
Running the test:
====
$ python -m unittest test_reswarn.py
./test_reswarn.py:6: ResourceWarning: unclosed file <_io.TextIOWrapper name='./test_reswarn.py' mode='r' encoding='UTF-8'>
self.assertIn("TestResourceWarning", open(__file__).read())
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
====
When running the unit test using unittest, ResourceWarning warnings are displayed. In my experience using open("filename") without explicitly closing the file is pretty common and would usually not be an error, since the file will be closed when the reference goes out of scope (or am I wrong?).
Therefore I believe that unittest should not emit ResourceWarning warnings. |
|
Date |
User |
Action |
Args |
2014-02-06 12:13:43 | Bernt.Røskar.Brenna | set | recipients:
+ Bernt.Røskar.Brenna |
2014-02-06 12:13:42 | Bernt.Røskar.Brenna | set | messageid: <1391688822.97.0.233110009283.issue20529@psf.upfronthosting.co.za> |
2014-02-06 12:13:42 | Bernt.Røskar.Brenna | link | issue20529 messages |
2014-02-06 12:13:42 | Bernt.Røskar.Brenna | create | |
|