diff --git a/Tests/helper.py b/Tests/helper.py index 3da2571f2..01fdd11cc 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -282,6 +282,19 @@ def is_win32(): return sys.platform.startswith("win32") +def is_win32_docker(): + try: + import winreg + + key = winreg.OpenKey( + winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control" + ) + winreg.QueryValueEx(key, "ContainerType") # fails if not in Docker container + return True + except (ImportError, OSError): + return False + + def is_pypy(): return hasattr(sys, "pypy_translation_info") diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index c36285451..988233fdf 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -6,13 +6,19 @@ import pytest from PIL import Image, ImageGrab -from .helper import assert_image, assert_image_equal_tofile, skip_unless_feature +from .helper import ( + assert_image, + assert_image_equal_tofile, + is_win32_docker, + skip_unless_feature, +) class TestImageGrab: @pytest.mark.skipif( sys.platform not in ("win32", "darwin"), reason="requires Windows or macOS" ) + @pytest.mark.skipif(is_win32_docker(), reason="running on headless Windows") def test_grab(self): for im in [ ImageGrab.grab(),