]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Optimize "open" method with context manager
authorxiexs <xiexs@cn.fujitsu.com>
Fri, 27 Nov 2015 08:41:52 +0000 (03:41 -0500)
committerxiexs <xiexs@cn.fujitsu.com>
Wed, 2 Dec 2015 11:10:31 +0000 (11:10 +0000)
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

index 1a50e3caf8ea5c3e820ca0f2c7d36b8ff11a7f87..644073979011aa8c41ca06990a8ca373aa04abe4 100644 (file)
@@ -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