test_grab_x11 failure when no X session is running
<!--
Thank you for reporting an issue.
Follow these guidelines to ensure your issue is handled properly.
If you have a ...
1. General question: consider asking the question on Stack Overflow
with the python-imaging-library tag:
* https://stackoverflow.com/questions/tagged/python-imaging-library
Do not ask a question in both places.
If you think you have found a bug or have an unexplained exception
then file a bug report here.
2. Bug report: include a self-contained, copy-pastable example that
generates the issue if possible. Be concise with code posted.
Guidelines on how to provide a good bug report:
* https://stackoverflow.com/help/mcve
Bug reports which follow these guidelines are easier to diagnose,
and are often handled much more quickly.
3. Feature request: do a quick search of existing issues
to make sure this has not been asked before.
We know asking good questions takes effort, and we appreciate your time.
Thank you.
-->
### What did you do?
I ran the pillow 12.2.0 test suite on a machine where XCB (X protocol) support is available, but without a running X session.
### What did you expect to happen?
All tests should pass.
### What actually happened?
`test_grab_x11` failed with:
```
....
> size, data = Image.core.grabscreen_x11(display_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E OSError: X connection failed: error 5
....
> raise subprocess.CalledProcessError(retcode, args)
E subprocess.CalledProcessError: Command '['gnome-screenshot', '-f', '/tmp/tmpqqqjkvf6.png']' returned non-zero exit status 1.
../build/prototype/i386/usr/lib/python3.13/vendor-packages/PIL/ImageGrab.py:135: CalledProcessError
-------------------------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------------------------
(gnome-screenshot:8318): Gtk-WARNING **: 16:20:16.856: cannot open display
....
```
### What are your OS, Python and Pillow versions?
* OS: Oracle Solaris
* Python: 3.11 and 3.13
* Pillow: 12.2.0
```text
--------------------------------------------------------------------
Pillow 12.2.0
Python 3.13.12 (main, Mar 24 2026, 07:17:40) [GCC 15.2.0]
--------------------------------------------------------------------
Python executable is /bin/python3
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /builds/pillow/build/prototype/i386/usr/lib/python3.13/vendor-packages/PIL
Binary Pillow modules loaded from /builds/pillow/build/prototype/i386/usr/lib/python3.13/vendor-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.2.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.14.2
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.6.0
*** AVIF support not installed
--- JPEG support ok, compiled for 9.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.3
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.2
--- LIBTIFF support ok, loaded 4.7.1
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
```
2 条评论