From 8ec6962daf5678519496cc04baf3c48645cc69fd Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Wed, 22 Jan 2020 12:56:07 +0100 Subject: test: prevent ResourceWarning in test_client Config files are written using file handles which are never closed. Under python 3.4 or later, that causes ResourceWarning warnings to be emitted. Change-Id: Ia3c11f61b62b367afe8f588816e3e8837835e835 --- tests/unit/test_client.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 32b5de527..ea94382b0 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -43,8 +43,8 @@ class TestTenantValidationClient(BaseClientTestCase): self.config.set( 'scheduler', 'tenant_config', os.path.join(FIXTURE_DIR, 'config/tenant-parser/simple.yaml')) - self.config.write( - open(os.path.join(self.test_root, 'tenant_ok.conf'), 'w')) + with open(os.path.join(self.test_root, 'tenant_ok.conf'), 'w') as f: + self.config.write(f) p = subprocess.Popen( [os.path.join(sys.prefix, 'bin/zuul'), '-c', os.path.join(self.test_root, 'tenant_ok.conf'), @@ -55,8 +55,8 @@ class TestTenantValidationClient(BaseClientTestCase): self.config.set( 'scheduler', 'tenant_config', os.path.join(FIXTURE_DIR, 'config/tenant-parser/invalid.yaml')) - self.config.write( - open(os.path.join(self.test_root, 'tenant_ko.conf'), 'w')) + with open(os.path.join(self.test_root, 'tenant_ko.conf'), 'w') as f: + self.config.write(f) p = subprocess.Popen( [os.path.join(sys.prefix, 'bin/zuul'), '-c', os.path.join(self.test_root, 'tenant_ko.conf'), @@ -76,8 +76,9 @@ class TestWebTokenClient(BaseClientTestCase): old_conf = io.StringIO() self.config.write(old_conf) self.config.remove_section('auth zuul_operator') - self.config.write( - open(os.path.join(self.test_root, 'no_zuul_operator.conf'), 'w')) + with open(os.path.join(self.test_root, + 'no_zuul_operator.conf'), 'w') as f: + self.config.write(f) p = subprocess.Popen( [os.path.join(sys.prefix, 'bin/zuul'), '-c', os.path.join(self.test_root, 'no_zuul_operator.conf'), @@ -98,8 +99,8 @@ class TestWebTokenClient(BaseClientTestCase): self.config.write(old_conf) self.config.add_section('auth someauth') self.config.set('auth someauth', 'driver', 'RS256withJWKS') - self.config.write( - open(os.path.join(self.test_root, 'JWKS.conf'), 'w')) + with open(os.path.join(self.test_root, 'JWKS.conf'), 'w') as f: + self.config.write(f) p = subprocess.Popen( [os.path.join(sys.prefix, 'bin/zuul'), '-c', os.path.join(self.test_root, 'JWKS.conf'), @@ -116,8 +117,8 @@ class TestWebTokenClient(BaseClientTestCase): def test_token_generation(self): """Test token generation""" - self.config.write( - open(os.path.join(self.test_root, 'good.conf'), 'w')) + with open(os.path.join(self.test_root, 'good.conf'), 'w') as f: + self.config.write(f) p = subprocess.Popen( [os.path.join(sys.prefix, 'bin/zuul'), '-c', os.path.join(self.test_root, 'good.conf'), -- cgit v1.2.1