Skip to contentSkip to conversation

tests/functional/m68k: Avoid ResourceWarning in the nextcube test

PATCH In review Thomas Huth 2 participants 2 messages Aug 30, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/functional/m68k: Avoid ResourceWarning in the nextcube test

From: Thomas Huth <[email protected]>

Since commit c3fd296cf7b1 ("functional: always enable all python warnings") we enabled more warnings for the functional tests. This triggers now a warning in the nextcube test:

tests/functional/m68k/test_nextcube.py:47: ResourceWarning:
unclosed file <_io.BufferedReader name='tests/functional/m68k/test_nextcube.NextCubeMachine.test_bootrom_framebuffer_size/scratch/dump.ppm'>
width, height = Image.open(screenshot_path).size

Use a proper "with" context to avoid it.

---
 tests/functional/m68k/test_nextcube.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/functional/m68k/test_nextcube.py +2 -1
index 13c72bd136a..c1610e58456 100755
@@ -44,7 +44,8 @@ def test_bootrom_framebuffer_size(self):
         self.check_bootrom_framebuffer(screenshot_path)
 
         from PIL import Image
-        width, height = Image.open(screenshot_path).size
+        with Image.open(screenshot_path) as image:
+                width, height = image.size
         self.assertEqual(width, 1120)
         self.assertEqual(height, 832)
 
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Thomas Huth

From: Thomas Huth <[email protected]>

Since commit c3fd296cf7b1 ("functional: always enable all python warnings") we enabled more warnings for the functional tests. This triggers now a warning in the nextcube test:

tests/functional/m68k/test_nextcube.py:47: ResourceWarning:
unclosed file <_io.BufferedReader name='tests/functional/m68k/test_nextcube.NextCubeMachine.test_bootrom_framebuffer_size/scratch/dump.ppm'>
width, height = Image.open(screenshot_path).size

Quoted 6 lines

Use a proper "with" context to avoid it.

---
 tests/functional/m68k/test_nextcube.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|