diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index fa2291582d4..98ce0541c46 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -1,4 +1,5 @@ import os +import shutil import subprocess import sys @@ -11,7 +12,9 @@ class TestImageGrab: @pytest.mark.skipif( - sys.platform not in ("win32", "darwin"), reason="requires Windows or macOS" + sys.platform not in ("win32", "darwin") + and not shutil.which("gnome-screenshot"), + reason="requires Windows or macOS, or Linux with gnome-screenshot", ) def test_grab(self): ImageGrab.grab() @@ -22,9 +25,11 @@ def test_grab(self): assert im.size == (40, 60) @skip_unless_feature("xcb") - def test_grab_x11(self): + def test_grab_xcb(self, monkeypatch): try: if sys.platform not in ("win32", "darwin"): + # test XCB is used when gnome-screenshot is not available + monkeypatch.setattr(shutil, "which", lambda x: False) ImageGrab.grab() ImageGrab.grab(xdisplay="") @@ -33,11 +38,6 @@ def test_grab_x11(self): @pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB") def test_grab_no_xcb(self): - if sys.platform not in ("win32", "darwin"): - with pytest.raises(OSError) as e: - ImageGrab.grab() - assert str(e.value).startswith("Pillow was built without XCB support") - with pytest.raises(OSError) as e: ImageGrab.grab(xdisplay="") assert str(e.value).startswith("Pillow was built without XCB support")