Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kepstin opened this issue Nov 1, 2022 · 2 comments · Fixed by #6712
Closed

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

kepstin opened this issue Nov 1, 2022 · 2 comments · Fixed by #6712

Comments

@kepstin
Copy link

kepstin commented Nov 1, 2022

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
@radarhere
Copy link
Member

Yes, #6361 didn't update the tests.

I've created PR #6712 to resolve this. Would you be able to test it?

@kepstin
Copy link
Author

kepstin commented Nov 1, 2022

I've tested the patch from #6712 and I've confirmed that the Pillow tests now pass in my build environment, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants