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 <>
Given the following file

import unittest

class TestResourceWarning(unittest.TestCase):
    def test_it(self):
        self.assertIn("TestResourceWarning", open(__file__).read())

Running the test:

$ python -m unittest
./ ResourceWarning: unclosed file <_io.TextIOWrapper name='./' mode='r' encoding='UTF-8'>
  self.assertIn("TestResourceWarning", open(__file__).read())
Ran 1 test in 0.000s


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:43Bernt.Røskar.Brennasetrecipients: + Bernt.Røskar.Brenna
2014-02-06 12:13:42Bernt.Røskar.Brennasetmessageid: <>
2014-02-06 12:13:42Bernt.Røskar.Brennalinkissue20529 messages
2014-02-06 12:13:42Bernt.Røskar.Brennacreate