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 Bernt.Røskar.Brenna
Recipients Bernt.Røskar.Brenna
Date 2014-02-06.12:13:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1391688822.97.0.233110009283.issue20529@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-02-06 12:13:43Bernt.Røskar.Brennasetrecipients: + Bernt.Røskar.Brenna
2014-02-06 12:13:42Bernt.Røskar.Brennasetmessageid: <1391688822.97.0.233110009283.issue20529@psf.upfronthosting.co.za>
2014-02-06 12:13:42Bernt.Røskar.Brennalinkissue20529 messages
2014-02-06 12:13:42Bernt.Røskar.Brennacreate