Browse Source

qubes/tests: skipping tests outside dom0

New variable and decorator enable skipping tests outside dom0, that is, without
connection to libvirtd.
Wojtek Porczyk 9 years ago
parent
commit
8ace0fa634
1 changed files with 23 additions and 0 deletions
  1. 23 0
      qubes/tests/__init__.py

+ 23 - 0
qubes/tests/__init__.py

@@ -3,8 +3,31 @@
 import collections
 import unittest
 
+import qubes.config
 import qubes.events
 
+
+#: :py:obj:`True` if running in dom0, :py:obj:`False` otherwise
+in_dom0 = False
+
+try:
+    import libvirt
+    libvirt.openReadOnly(qubes.config.defaults['libvirt_uri']).close()
+    in_dom0 = True
+    del libvirt
+except libvirt.libvirtError:
+    pass
+
+
+def skipUnlessDom0(test_item):
+    '''Decorator that skips test outside dom0.
+
+    Some tests (especially integration tests) have to be run in more or less
+    working dom0. This is checked by connecting to libvirt.
+    '''
+    return unittest.skipUnless(in_dom0, 'outside dom0')(test_item)
+
+
 class TestEmitter(qubes.events.Emitter):
     '''Dummy event emitter which records events fired on it.