From 659281bf2374b9d85dc0d2b041a593b8dbef8d98 Mon Sep 17 00:00:00 2001 From: Justin Mahlik <38999128+jmahlik@users.noreply.github.com> Date: Tue, 27 Feb 2024 15:10:37 -0600 Subject: [PATCH] fix: properly close files in lineage queries and tests Closes #4458 --- src/sagemaker/lineage/query.py | 4 ++-- tests/data/sip/training.py | 3 ++- .../sagemaker/lineage/test_lineage_visualize.py | 4 ++-- tests/integ/sagemaker/workflow/test_workflow.py | 3 ++- tests/integ/test_sagemaker_config.py | 6 ++++-- tests/unit/sagemaker/local/test_local_image.py | 12 ++++++++---- tests/unit/sagemaker/serializers/test_serializers.py | 6 ++++-- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/sagemaker/lineage/query.py b/src/sagemaker/lineage/query.py index 182f117913..3e2003674b 100644 --- a/src/sagemaker/lineage/query.py +++ b/src/sagemaker/lineage/query.py @@ -335,8 +335,8 @@ def _get_legend_line(self, component_name): def _add_legend(self, path): """Embed legend to html file generated by pyvis.""" - f = open(path, "r") - content = self.BeautifulSoup(f, "html.parser") + with open(path, "r") as f: + content = self.BeautifulSoup(f, "html.parser") legend = """