Commit 1e284d2b authored by Katerina Koukiou's avatar Katerina Koukiou

tests: {interface, node_device}_create should be used as setup fixtures

* node_device_create was a fixture but we were calling it as normal function,
thus it got triggered twice.
* interface_create was not a fixture.

This patch makes sure that the setup work these two functions are doing, will
run before the actual test call phase.
Signed-off-by: 's avatarKaterina Koukiou <kkoukiou@redhat.com>
Reviewed-by: 's avatarJán Tomko <jtomko@redhat.com>
parent 9cfc3a48
...@@ -71,6 +71,7 @@ class BaseTestClass(): ...@@ -71,6 +71,7 @@ class BaseTestClass():
if self.timeout: if self.timeout:
raise TimeoutError() raise TimeoutError()
@pytest.fixture
def interface_create(self): def interface_create(self):
""" Fixture to define dummy interface on the test driver """ Fixture to define dummy interface on the test driver
......
...@@ -88,14 +88,15 @@ class TestConnect(libvirttest.BaseTestClass): ...@@ -88,14 +88,15 @@ class TestConnect(libvirttest.BaseTestClass):
path = self.connect.InterfaceDefineXML(xmldata.minimal_interface_xml, 0) path = self.connect.InterfaceDefineXML(xmldata.minimal_interface_xml, 0)
assert isinstance(path, dbus.ObjectPath) assert isinstance(path, dbus.ObjectPath)
@pytest.mark.usefixtures("interface_create")
@pytest.mark.parametrize("lookup_method_name,lookup_item", [ @pytest.mark.parametrize("lookup_method_name,lookup_item", [
("InterfaceLookupByName", 'Name'), ("InterfaceLookupByName", 'Name'),
("InterfaceLookupByMAC", 'MAC'), ("InterfaceLookupByMAC", 'MAC'),
]) ])
def test_connect_interface_lookup_by_property(self, lookup_method_name, lookup_item): def test_connect_interface_lookup_by_property(self, lookup_method_name, lookup_item, interface_create):
"""Parameterized test for all InterfaceLookupBy* API calls of Connect interface """Parameterized test for all InterfaceLookupBy* API calls of Connect interface
""" """
original_path,_ = self.interface_create() original_path,_ = interface_create
obj = self.bus.get_object('org.libvirt', original_path) obj = self.bus.get_object('org.libvirt', original_path)
prop = obj.Get('org.libvirt.Interface', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE) prop = obj.Get('org.libvirt.Interface', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE)
path = getattr(self.connect, lookup_method_name)(prop) path = getattr(self.connect, lookup_method_name)(prop)
...@@ -164,10 +165,10 @@ class TestConnect(libvirttest.BaseTestClass): ...@@ -164,10 +165,10 @@ class TestConnect(libvirttest.BaseTestClass):
@pytest.mark.parametrize("lookup_method_name,lookup_item", [ @pytest.mark.parametrize("lookup_method_name,lookup_item", [
("NodeDeviceLookupByName", 'Name'), ("NodeDeviceLookupByName", 'Name'),
]) ])
def test_connect_node_device_lookup_by_property(self, lookup_method_name, lookup_item): def test_connect_node_device_lookup_by_property(self, lookup_method_name, lookup_item, node_device_create):
"""Parameterized test for all NodeDeviceLookupBy* API calls of Connect interface """Parameterized test for all NodeDeviceLookupBy* API calls of Connect interface
""" """
original_path = self.node_device_create() original_path = node_device_create
obj = self.bus.get_object('org.libvirt', original_path) obj = self.bus.get_object('org.libvirt', original_path)
prop = obj.Get('org.libvirt.NodeDevice', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE) prop = obj.Get('org.libvirt.NodeDevice', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE)
path = getattr(self.connect, lookup_method_name)(prop) path = getattr(self.connect, lookup_method_name)(prop)
......
...@@ -2,33 +2,35 @@ ...@@ -2,33 +2,35 @@
import dbus import dbus
import libvirttest import libvirttest
import pytest
@pytest.mark.usefixtures("interface_create")
class TestInterface(libvirttest.BaseTestClass): class TestInterface(libvirttest.BaseTestClass):
""" Tests for methods and properties of the Interface interface """ Tests for methods and properties of the Interface interface
""" """
def test_interface_undefine(self): def test_interface_undefine(self, interface_create):
_,interface_obj = self.interface_create() _,interface_obj = interface_create
interface_obj.Destroy(0) interface_obj.Destroy(0)
interface_obj.Undefine() interface_obj.Undefine()
def test_interface_destroy(self): def test_interface_destroy(self, interface_create):
_,interface_obj = self.interface_create() _,interface_obj = interface_create
interface_obj.Destroy(0) interface_obj.Destroy(0)
def test_interface_create(self): def test_interface_create(self, interface_create):
_,interface_obj = self.interface_create() _,interface_obj = interface_create
interface_obj.Destroy(0) interface_obj.Destroy(0)
interface_obj.Create(0) interface_obj.Create(0)
def test_interface_get_xml_description(self): def test_interface_get_xml_description(self, interface_create):
_,interface_obj = self.interface_create() _,interface_obj = interface_create
assert isinstance(interface_obj.GetXMLDesc(0), dbus.String) assert isinstance(interface_obj.GetXMLDesc(0), dbus.String)
def test_interface_properties_type(self): def test_interface_properties_type(self, interface_create):
""" Ensure correct return type for Interface properties """ Ensure correct return type for Interface properties
""" """
test_interface_path,_ = self.interface_create() test_interface_path,_ = interface_create
obj = self.bus.get_object('org.libvirt', test_interface_path) obj = self.bus.get_object('org.libvirt', test_interface_path)
props = obj.GetAll('org.libvirt.Interface', dbus_interface=dbus.PROPERTIES_IFACE) props = obj.GetAll('org.libvirt.Interface', dbus_interface=dbus.PROPERTIES_IFACE)
assert isinstance(props['Name'], dbus.String) assert isinstance(props['Name'], dbus.String)
......
...@@ -10,7 +10,7 @@ class TestNodeDevice(libvirttest.BaseTestClass): ...@@ -10,7 +10,7 @@ class TestNodeDevice(libvirttest.BaseTestClass):
""" Tests for methods and properties of the NodeDevice interface """ Tests for methods and properties of the NodeDevice interface
""" """
def test_node_device_destroy(self): def test_node_device_destroy(self, node_device_create):
def node_device_deleted(path, event, _detail): def node_device_deleted(path, event, _detail):
if event != libvirttest.NodeDeviceEvent.DELETED: if event != libvirttest.NodeDeviceEvent.DELETED:
return return
...@@ -19,29 +19,29 @@ class TestNodeDevice(libvirttest.BaseTestClass): ...@@ -19,29 +19,29 @@ class TestNodeDevice(libvirttest.BaseTestClass):
self.connect.connect_to_signal('NodeDeviceEvent', node_device_deleted) self.connect.connect_to_signal('NodeDeviceEvent', node_device_deleted)
test_node_device_path = self.node_device_create() test_node_device_path = node_device_create
obj = self.bus.get_object('org.libvirt', test_node_device_path) obj = self.bus.get_object('org.libvirt', test_node_device_path)
interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice') interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
interface_obj.Destroy() interface_obj.Destroy()
self.main_loop() self.main_loop()
def test_node_device_get_xml_description(self): def test_node_device_get_xml_description(self, node_device_create):
test_node_device_path = self.node_device_create() test_node_device_path = node_device_create
obj = self.bus.get_object('org.libvirt', test_node_device_path) obj = self.bus.get_object('org.libvirt', test_node_device_path)
interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice') interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
assert isinstance(interface_obj.GetXMLDesc(0), dbus.String) assert isinstance(interface_obj.GetXMLDesc(0), dbus.String)
def test_node_device_list_caps(self): def test_node_device_list_caps(self, node_device_create):
test_node_device_path = self.node_device_create() test_node_device_path = node_device_create
obj = self.bus.get_object('org.libvirt', test_node_device_path) obj = self.bus.get_object('org.libvirt', test_node_device_path)
interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice') interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
assert isinstance(interface_obj.ListCaps(), dbus.Array) assert isinstance(interface_obj.ListCaps(), dbus.Array)
def test_node_device_properties_type(self): def test_node_device_properties_type(self, node_device_create):
""" Ensure correct return type for NodeDevice properties """ Ensure correct return type for NodeDevice properties
""" """
test_node_device_path = self.node_device_create() test_node_device_path = node_device_create
obj = self.bus.get_object('org.libvirt', test_node_device_path) obj = self.bus.get_object('org.libvirt', test_node_device_path)
props = obj.GetAll('org.libvirt.NodeDevice', dbus_interface=dbus.PROPERTIES_IFACE) props = obj.GetAll('org.libvirt.NodeDevice', dbus_interface=dbus.PROPERTIES_IFACE)
assert isinstance(props['Name'], dbus.String) assert isinstance(props['Name'], dbus.String)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment