Skip to content

TestImageGrab.test_grab_no_xcb fails when gnome-screenshot is installed #6710

@kepstin

Description

@kepstin

What did you do?

Ran Pillow tests with gnome-screenshot installed.

What did you expect to happen?

The tests would all pass!

What actually happened?

The test TestImageGrab.test_grab_no_xcb fails, with the following output:

__________________________________________________ TestImageGrab.test_grab_no_xcb __________________________________________________
                                                                                                                                    
self = <Tests.test_imagegrab.TestImageGrab object at 0x7f8aaa979a80>                                                                
                                                                                                                                    
    @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")
E           assert False                                          
E            +  where False = <built-in method startswith of str object at 0x7f8aaa62a730>('Pillow was built without XCB support')  
E            +    where <built-in method startswith of str object at 0x7f8aaa62a730> = "cannot identify image file '/var/tmp/paludis
/build/dev-python-Pillow-9.3.0/temp/tmpz2e7yvdk.png'".startswith
E            +      where "cannot identify image file '/var/tmp/paludis/build/dev-python-Pillow-9.3.0/temp/tmpz2e7yvdk.png'" = str(U
nidentifiedImageError("cannot identify image file '/var/tmp/paludis/build/dev-python-Pillow-9.3.0/temp/tmpz2e7yvdk.png'"))
E            +        where UnidentifiedImageError("cannot identify image file '/var/tmp/paludis/build/dev-python-Pillow-9.3.0/temp/
tmpz2e7yvdk.png'") = <ExceptionInfo UnidentifiedImageError("cannot identify image file '/var/tmp/paludis/build/dev-python-Pillow-9.3
.0/temp/tmpz2e7yvdk.png'") tblen=3>.value

Tests/test_imagegrab.py:39: AssertionError
------------------------------------------------------- Captured stderr call -------------------------------------------------------

(gnome-screenshot:1481061): Gtk-WARNING **: 13:55:04.539: cannot open display: 

It looks like what is happening here is that the ImageGrab.grab() method has a fallback which runs gnome-screenshot (if installed) when XCB is disabled. In my case, the tests are running in a sandboxed package build environment, so gnome-screenshot fails to grab an image, resulting in an error message that is different from the expected error.

Of course, if gnome-screenshot had succeeded, the test would still fail, since it's expecting an error to be raised, not a successful screenshot to be taken.

This issue appears to have been introduced by #6361

What are your OS, Python and Pillow versions?

  • OS: Exherbo Linux, amd64
  • Python: 3.10.8
  • Pillow: 9.3.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions