From f9be5d886dc07576eea179612fc00138e58fad28 Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Wed, 31 May 2023 16:40:48 -0400 Subject: [PATCH] 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 --- neutron/tests/unit/common/ovn/test_utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/neutron/tests/unit/common/ovn/test_utils.py b/neutron/tests/unit/common/ovn/test_utils.py index efc84c23007..0d84f4e5f89 100644 --- a/neutron/tests/unit/common/ovn/test_utils.py +++ b/neutron/tests/unit/common/ovn/test_utils.py @@ -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)