Fix 'consider-using-with' warning

Test test_get_system_dns_resolvers() open codes an
open() and close(), use 'with' instead to be safer.
Seems to be the only place in the tree we did this.

Trivialfix

Change-Id: Icb76861f82838f21440f29ed4b5c97be3a410360
This commit is contained in:
Brian Haley
2023-05-31 16:40:48 -04:00
parent 4d7f1b7bca
commit f9be5d886d
+2 -3
View File
@@ -52,9 +52,8 @@ class TestUtils(base.BaseTestCase):
def test_get_system_dns_resolvers(self):
tempdir = self.useFixture(fixtures.TempDir()).path
resolver_file_name = tempdir + '/resolv.conf'
tmp_resolv_file = open(resolver_file_name, 'w')
tmp_resolv_file.writelines(RESOLV_CONF_TEMPLATE)
tmp_resolv_file.close()
with open(resolver_file_name, 'w') as f:
f.writelines(RESOLV_CONF_TEMPLATE)
expected_dns_resolvers = RESOLV_DNS_SERVERS
observed_dns_resolvers = utils.get_system_dns_resolvers(
resolver_file=resolver_file_name)