[pygobject/tests-fail-gtk-init] tests: error out if gtk is available but gtk_init() fails



commit 21763e9dbd3f3f432937a33465730eca16280384
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Fri Sep 14 18:45:58 2018 +0200

    tests: error out if gtk is available but gtk_init() fails
    
    In case tests are run on a headless system without xvfb then the gtk
    import will succeed but it will crash in the first gdk/gtk test.
    
    Error out early instead.

 tests/__init__.py | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/tests/__init__.py b/tests/__init__.py
index 1ab73f0d..79b8c808 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -128,6 +128,15 @@ def init_test_environ():
     # always on for the tests.
     warnings.simplefilter('default', gi.PyGIDeprecationWarning)
 
+    # Otherwise we crash on the first gtk use when e.g. DISPLAY isn't set
+    try:
+        from gi.repository import Gtk
+    except ImportError:
+        pass
+    else:
+        if not Gtk.init_check([])[0]:
+            raise RuntimeError("Gtk available, but Gtk.init_check() failed")
+
 
 init_test_environ()
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]