Merge pull request #10522 from AlanCoding/close_file

Close file before returning

Resolves
/home/alancoding/repos/tower-qa/tests/lib/plugins/pytest_restqa/plugin.py:122: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/alancoding/repos/tower-qa/scripts/resource_loading/data_latest_loading.yml' mode='r' encoding='UTF-8'>
  qe_config.resources = PseudoNamespace(yaml_file.load_file(config.option.resource_file))

We have this same pattern earlier in the file.

Reviewed-by: Shane McDonald <me@shanemcd.com>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-06-28 17:52:37 +00:00 committed by GitHub
commit c09cad3e6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,9 +89,9 @@ def load_file(filename):
path = local(filename)
if path.check():
fp = path.open()
# FIXME - support load_all()
return yaml.load(fp, Loader=Loader)
with open(path, 'r') as fp:
# FIXME - support load_all()
return yaml.load(fp, Loader=Loader)
else:
msg = 'Unable to load data file at %s' % path
raise Exception(msg)