qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 5/6] qtest.py: add a simple main() which calls unitt


From: Philippe Mathieu-Daudé
Subject: [Qemu-devel] [PATCH 5/6] qtest.py: add a simple main() which calls unittest.main()
Date: Wed, 13 Dec 2017 18:35:56 -0300

We can now write complex qtests with a high-level language (Python).
(partly copied from iotests::main)

Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
 scripts/qtest.py | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/scripts/qtest.py b/scripts/qtest.py
index 429eb67c2a..581451836c 100644
--- a/scripts/qtest.py
+++ b/scripts/qtest.py
@@ -226,3 +226,36 @@ def verify_machine(supported_machines):
 
     if True not in [x in machines for x in supported_machines]:
         notrun('not machine suitable for this test')
+
+def main(supported_oses=['linux'], supported_machines=['any']):
+    '''Run tests'''
+
+    global debug
+
+    verify_platform(supported_oses)
+    verify_machine(supported_machines)
+
+    verbosity = 0
+    level = logging.WARN
+    if '-d' in sys.argv:
+        verbosity = 2
+        level = logging.DEBUG
+    if '-v' in sys.argv:
+        verbosity = 1
+        level = logging.INFO
+    if '-q' in sys.argv:
+        level = logging.NOTSET
+
+    import StringIO
+    output = sys.stdout if verbosity else StringIO.StringIO()
+
+    logging.basicConfig(level=level)
+
+    class MyTestRunner(unittest.TextTestRunner):
+        def __init__(self, stream=output, descriptions=True,
+                     verbosity=verbosity):
+            unittest.TextTestRunner.__init__(self, stream, descriptions,
+                                             verbosity)
+
+    # unittest.main() will use sys.exit() so expect a SystemExit exception
+    unittest.main(testRunner=MyTestRunner)
-- 
2.15.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]