qubes/tests: skipping tests outside dom0

New variable and decorator enable skipping tests outside dom0, that is, without
connection to libvirtd.
This commit is contained in:
Wojtek Porczyk 2015-01-05 17:01:13 +01:00
parent 613b03d277
commit 8ace0fa634

View File

@ -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.