diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_inventory.py | 13 | ||||
-rw-r--r-- | tests/unit/test_v3.py | 3 |
2 files changed, 11 insertions, 5 deletions
diff --git a/tests/unit/test_inventory.py b/tests/unit/test_inventory.py index 5b30a139f..5cafe2ddf 100644 --- a/tests/unit/test_inventory.py +++ b/tests/unit/test_inventory.py @@ -57,7 +57,8 @@ class TestInventoryBase(ZuulTestCase): build = self.getBuildByName(name) inv_path = os.path.join(build.jobdir.root, 'ansible', 'inventory.yaml') - inventory = yaml.safe_load(open(inv_path, 'r')) + with open(inv_path, 'r') as f: + inventory = yaml.safe_load(f) return inventory def _get_setup_inventory(self, name): @@ -65,7 +66,9 @@ class TestInventoryBase(ZuulTestCase): build = self.getBuildByName(name) setup_inv_path = build.jobdir.setup_playbook.inventory - return yaml.ansible_unsafe_load(open(setup_inv_path, 'r')) + with open(setup_inv_path, 'r') as f: + inventory = yaml.ansible_unsafe_load(f) + return inventory def runJob(self, name): self.hold_jobs_in_queue = False @@ -409,10 +412,12 @@ class TestAnsibleInventory(AnsibleZuulTestCase): build = self.history[0] inv_path = os.path.join(build.jobdir.root, 'ansible', 'inventory.yaml') - inventory = yaml.safe_load(open(inv_path, 'r')) + with open(inv_path, 'r') as f: + inventory = yaml.safe_load(f) zv_path = os.path.join(build.jobdir.root, 'ansible', 'zuul_vars.yaml') - zv = yaml.safe_load(open(zv_path, 'r')) + with open(zv_path, 'r') as f: + zv = yaml.safe_load(f) # TODO(corvus): zuul vars aren't really stored here anymore; # rework these tests to examine them separately. diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py index 81d95927a..de8b8f3ad 100644 --- a/tests/unit/test_v3.py +++ b/tests/unit/test_v3.py @@ -5283,7 +5283,8 @@ class TestRoleBranches(RoleTestCase): def getBuildInventory(self, name): build = self.getBuildByName(name) inv_path = os.path.join(build.jobdir.root, 'ansible', 'inventory.yaml') - inventory = yaml.safe_load(open(inv_path, 'r')) + with open(inv_path, 'r') as f: + inventory = yaml.safe_load(f) return inventory def getCheckout(self, build, path): |