diff --git a/plugin/src/py/android_screenshot_tests/pull_screenshots.py b/plugin/src/py/android_screenshot_tests/pull_screenshots.py index b642cd33..20b1f1ec 100755 --- a/plugin/src/py/android_screenshot_tests/pull_screenshots.py +++ b/plugin/src/py/android_screenshot_tests/pull_screenshots.py @@ -113,7 +113,8 @@ def generate_html( # and returns a url to an image from a previous run of the test, # old_imgs_data a dict that will be used in the test_img_api url. # Creates the html for showing a before and after comparison of the images. - screenshots = json.load(open(join(output_dir, "metadata.json"))) + with open(join(output_dir, "metadata.json")) as m: + screenshots = json.load(m) alternate = False index_html = abspath(join(output_dir, "index.html")) with codecs.open(index_html, mode="w", encoding="utf-8") as html: @@ -530,7 +531,8 @@ def move_all_files_to_different_directory(source_dir, target_dir): def _summary(dir): - metadataJson = json.load(open(join(dir, "metadata.json"))) + with open(join(dir, "metadata.json")) as f: + metadataJson = json.load(f) count = len(metadataJson) print("Found %d screenshots" % count) diff --git a/plugin/src/py/android_screenshot_tests/recorder.py b/plugin/src/py/android_screenshot_tests/recorder.py index e990c454..d7e18bee 100644 --- a/plugin/src/py/android_screenshot_tests/recorder.py +++ b/plugin/src/py/android_screenshot_tests/recorder.py @@ -71,8 +71,8 @@ def _copy(self, name, w, h): im.close() def _get_metadata_json(self): - file = open(join(self._input, "metadata.json"), "r") - return json.load(file) + with open(join(self._input, "metadata.json"), "r") as f: + return json.load(f) def _record(self): metadata = self._get_metadata_json()