[PATCH python 1/2] Add support for running unit tests with nose

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

 



Make the 'python setup.py test' able to run unit tests
found under tests/ through the 'nosetests' command

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 setup.py           |  5 +++++
 tests/test_conn.py | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 tests/test_conn.py

diff --git a/setup.py b/setup.py
index 773cef3..cfbbe2c 100755
--- a/setup.py
+++ b/setup.py
@@ -267,7 +267,12 @@ class my_test(Command):
 
         apis = get_api_xml_files()
 
+        if "PYTHONPATH" in os.environ:
+            os.environ["PYTHONPATH"] = self.build_platlib + ":" + os.environ["PYTHONPATH"]
+        else:
+            os.environ["PYTHONPATH"] = self.build_platlib
         self.spawn([sys.executable, "sanitytest.py", self.build_platlib, apis[0]])
+        self.spawn(["nosetests"])
 
 
 class my_clean(clean):
diff --git a/tests/test_conn.py b/tests/test_conn.py
new file mode 100644
index 0000000..9fee099
--- /dev/null
+++ b/tests/test_conn.py
@@ -0,0 +1,16 @@
+
+import unittest
+import libvirt
+
+class TestLibvirtConn(unittest.TestCase):
+    def setUp(self):
+        self.conn = libvirt.open("test:///default")
+
+    def tearDown(self):
+        self.conn = None
+
+    def testConnDomainList(self):
+        doms = self.conn.listAllDomains()
+        self.assertEquals(len(doms), 1)
+        self.assertEquals(type(doms[0]), libvirt.virDomain)
+        self.assertEquals(doms[0].name(), "test")
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]