From da9cc1357fed234acd05ba9c8ba1f66e528f8db9 Mon Sep 17 00:00:00 2001 From: xiexs Date: Fri, 27 Nov 2015 03:41:52 -0500 Subject: [PATCH] Optimize "open" method with context manager Replace the classic open() method with opening context manager to open file so that the file will be closed even if an exception occurs. Change-Id: I0d53b7a38fee6a2ef8ce74496d220adc954afb98 --- neutron/tests/tempest/common/accounts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neutron/tests/tempest/common/accounts.py b/neutron/tests/tempest/common/accounts.py index 1a50e3caf..644073979 100644 --- a/neutron/tests/tempest/common/accounts.py +++ b/neutron/tests/tempest/common/accounts.py @@ -28,8 +28,8 @@ LOG = logging.getLogger(__name__) def read_accounts_yaml(path): - yaml_file = open(path, 'r') - accounts = yaml.load(yaml_file) + with open(path, 'r') as yaml_file: + accounts = yaml.load(yaml_file) return accounts -- 2.45.2