diff --git a/tests/test_default_tolerance.py b/tests/test_default_tolerance.py index 802527f..e9b154e 100644 --- a/tests/test_default_tolerance.py +++ b/tests/test_default_tolerance.py @@ -9,11 +9,11 @@ @pytest.fixture(scope="module") def baseline_image(tmp_path_factory): path = Path(__file__).parent / "baseline" / "2.0.x" / f"{TEST_NAME}.png" - image = Image.open(path) - draw = ImageDraw.Draw(image) - draw.rectangle(((0, 0), (100, 100)), fill="red") - output = tmp_path_factory.mktemp("data") / f"{TEST_NAME}.png" - image.save(output) + with Image.open(path) as image: + draw = ImageDraw.Draw(image) + draw.rectangle(((0, 0), (100, 100)), fill="red") + output = tmp_path_factory.mktemp("data") / f"{TEST_NAME}.png" + image.save(output) return output diff --git a/tests/test_deterministic.py b/tests/test_deterministic.py index 22ab49f..edd26b8 100644 --- a/tests/test_deterministic.py +++ b/tests/test_deterministic.py @@ -113,7 +113,8 @@ def test_mpl(): assert key_in_file else: # "eps" or "png" - actual_metadata = Image.open(str(baseline_image)).info + with Image.open(str(baseline_image)) as image: + actual_metadata = image.info for k, expected in deterministic_metadata.items(): actual = actual_metadata.get(k, None) if success_expected: # metadata keys should not be in the file