Browse Source

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
changes/82/703782/1
Antoine Musso 1 year ago
parent
commit
8ec6962daf
1 changed files with 11 additions and 10 deletions
  1. +11
    -10
      tests/unit/test_client.py

+ 11
- 10
tests/unit/test_client.py View File

@ -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'),


Loading…
Cancel
Save