From b1e47b43f3d2b972057ebe4c564b0ed03d39cd3d Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 16 Sep 2017 11:23:22 -0700 Subject: Clean up resource warnings during tests When tests are invoked with the Python flag -Wall, warnings appear in the form of: ResourceWarning: unclosed file ... Close all files and resources deterministically to avoid such warnings. Most often, easiest to do using a context manager. --- pkg_resources/tests/test_pkg_resources.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pkg_resources/tests') diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 49bf7a04..c6a7ac97 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -92,8 +92,8 @@ class TestZipProvider(object): ts = timestamp(self.ref_time) os.utime(filename, (ts, ts)) filename = zp.get_resource_filename(manager, 'data.dat') - f = open(filename) - assert f.read() == 'hello, world!' + with open(filename) as f: + assert f.read() == 'hello, world!' manager.cleanup_resources() -- cgit v1.2.3