diff options
author | Antoine Musso <hashar@free.fr> | 2020-01-22 12:56:07 +0100 |
---|---|---|
committer | Antoine Musso <hashar@free.fr> | 2020-01-22 12:56:07 +0100 |
commit | 8ec6962daf5678519496cc04baf3c48645cc69fd (patch) | |
tree | f39aca0343008d81b0e8b59f037e3d8938867545 | |
parent | acfe744db34293c9f6e70c59de0cbd676bf57938 (diff) | |
download | zuul-8ec6962daf5678519496cc04baf3c48645cc69fd.tar.gz |
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
-rw-r--r-- | tests/unit/test_client.py | 21 |
1 files changed, 11 insertions, 10 deletions
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'), |