Skip to content

Commit 2b1b8d7

Browse files
Merge pull request #222 from ConorMacBride/fix-unclosed-test-files
Fix unclosed test files
2 parents 3bd3703 + a9713dc commit 2b1b8d7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

tests/test_default_tolerance.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
@pytest.fixture(scope="module")
1010
def baseline_image(tmp_path_factory):
1111
path = Path(__file__).parent / "baseline" / "2.0.x" / f"{TEST_NAME}.png"
12-
image = Image.open(path)
13-
draw = ImageDraw.Draw(image)
14-
draw.rectangle(((0, 0), (100, 100)), fill="red")
15-
output = tmp_path_factory.mktemp("data") / f"{TEST_NAME}.png"
16-
image.save(output)
12+
with Image.open(path) as image:
13+
draw = ImageDraw.Draw(image)
14+
draw.rectangle(((0, 0), (100, 100)), fill="red")
15+
output = tmp_path_factory.mktemp("data") / f"{TEST_NAME}.png"
16+
image.save(output)
1717
return output
1818

1919

tests/test_deterministic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def test_mpl():
113113
assert key_in_file
114114

115115
else: # "eps" or "png"
116-
actual_metadata = Image.open(str(baseline_image)).info
116+
with Image.open(str(baseline_image)) as image:
117+
actual_metadata = image.info
117118
for k, expected in deterministic_metadata.items():
118119
actual = actual_metadata.get(k, None)
119120
if success_expected: # metadata keys should not be in the file

0 commit comments

Comments
 (0)