[PATCH] python/osmo-python-tests[master]: osmoutil: add pick_test() to pick unittest tests by name

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Feb 28 02:10:50 UTC 2017


Review at  https://gerrit.osmocom.org/1935

osmoutil: add pick_test() to pick unittest tests by name

Change-Id: I92f90c334169f31920c63dd5c5ac8dac215065e6
---
M osmopy/osmoutil.py
1 file changed, 22 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/35/1935/1

diff --git a/osmopy/osmoutil.py b/osmopy/osmoutil.py
index cb3cb6a..faedc43 100755
--- a/osmopy/osmoutil.py
+++ b/osmopy/osmoutil.py
@@ -19,6 +19,7 @@
 import sys
 import importlib
 import time
+import unittest
 
 
 """Run a command, with stdout and stderr directed to devnull"""
@@ -68,3 +69,24 @@
         else:
             print >> sys.stderr, "set osmoappdesc location with -p <dir>"
         sys.exit(1)
+
+
+def pick_tests(suite, *name_snippets):
+    '''for unittest: Non-standard way of picking only selected tests to run,
+       by name.  Kind of stupid of python unittest to not provide this feature
+       more easily.'''
+
+    new_tests = []
+    for t in suite._tests:
+        if isinstance(t, unittest.suite.TestSuite):
+            pick_tests(t, *name_snippets)
+            new_tests.append(t)
+            continue
+
+        if not isinstance(t, unittest.TestCase):
+            new_tests.append(t)
+            continue
+
+        if any([n.lower() in t._testMethodName.lower() for n in name_snippets]):
+            new_tests.append(t)
+    suite._tests = new_tests

-- 
To view, visit https://gerrit.osmocom.org/1935
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I92f90c334169f31920c63dd5c5ac8dac215065e6
Gerrit-PatchSet: 1
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list