[issue20529] Unittest displays ResourceWarning warnings when running tests, it probably should not

Bernt Røskar Brenna report at bugs.python.org
Thu Feb 6 13:13:43 CET 2014


New submission from Bernt Røskar Brenna:

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.

----------
components: Library (Lib)
messages: 210377
nosy: Bernt.Røskar.Brenna
priority: normal
severity: normal
status: open
title: Unittest displays ResourceWarning warnings when running tests, it probably should not
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20529>
_______________________________________


More information about the Python-bugs-list mailing list