From c09461103aad9913f73bf01166be731303594721 Mon Sep 17 00:00:00 2001 From: nulano Date: Sun, 1 Mar 2020 20:16:29 +0000 Subject: [PATCH] skip ImageGrab test on Windows in Docker --- Tests/helper.py | 13 +++++++++++++ Tests/test_imagegrab.py | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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(),