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

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Mar 6 14:31:52 UTC 2017


Neels Hofmeyr has submitted this change and it was merged.

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


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

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

Approvals:
  Neels Hofmeyr: Looks good to me, approved
  Harald Welte: Looks good to me, but someone else must approve
  Holger Freyther: Looks good to me, but someone else must approve



diff --git a/osmopy/osmoutil.py b/osmopy/osmoutil.py
index 01f74cc..87203d5 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"""
@@ -69,3 +70,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: merged
Gerrit-Change-Id: I92f90c334169f31920c63dd5c5ac8dac215065e6
Gerrit-PatchSet: 2
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list