Description
Describe the bug
A clear and concise description of what the bug is.
Continuing from #4456 there's more unclosed files in src and tests. Use with statements so they are always closed. May help reduce flakey tests since most of them are in tests.
I'll submit a PR to fix these separately since they are less impactful/user facing than #4456.
rg -e '[^with] open\(' ./src/ ./tests/
./tests/unit\sagemaker\workflow\test_repack_model_script.py
35: open(fake_model_path, "w")
75: open(fake_model_path, "w")
119: open(fake_model_path, "w")
./tests/unit\sagemaker\serializers\test_serializers.py
348: validation_image_data = open(validation_image_file_path, "rb").read()
356: validation_image_data = open(validation_image_file_path, "rb").read()
./tests/unit\sagemaker\local\test_local_image.py
371: open(os.path.join(volume, f), "a").close()
./tests/unit\sagemaker\config\test_config.py
37: return open(config_file_path, "r").read()
231: config_file_as_yaml = open(config_file_content_path, "r").read()
./tests/integ\test_sagemaker_config.py
174: config_file_1_as_yaml = open(config_file_1_local_path, "r").read()
./tests/integ\sagemaker\workflow\test_workflow.py
546: json.dump(ingestion_only_flow, open(temp_flow_path, "w"))
./tests/integ\sagemaker\lineage\test_lineage_visualize.py
145: fo = open("testGraph.html", "r")
./tests/integ\lock.py
30: f = open(path, "w")
./tests/data\sip\training.py
76: pkl.dump(bst, open(model_dir + "/model.bin", "wb"))
./src/sagemaker\lineage\query.py
338: f = open(path, "r")
To reproduce
A clear, step-by-step set of instructions to reproduce the bug.
The provided code need to be complete and runnable, if additional data is needed, please include them in the issue.
Run pytest with warnings as errors, there will be resource warnings for unclosed files.
python -X dev -X tracemalloc=20 -m pytest ./tests/unit/ -W error
Expected behavior
A clear and concise description of what you expected to happen.
Don't leak files.
Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.
System information
A description of your system. Please provide: windows
- SageMaker Python SDK version: master
- Framework name (eg. PyTorch) or algorithm (eg. KMeans): n/a
- Framework version: n/a
- Python version: 3.11
- CPU or GPU: cpu
- Custom Docker image (Y/N): n
Additional context
Add any other context about the problem here.