All of lore.kernel.org
 help / color / mirror / Atom feed
From: Noa Osherovich <noaos@mellanox.com>
To: dledford@redhat.com, jgg@mellanox.com, leonro@mellanox.com
Cc: linux-rdma@vger.kernel.org, Noa Osherovich <noaos@mellanox.com>
Subject: [PATCH rdma-core 12/14] tests: Fix test locating process
Date: Mon, 19 Aug 2019 09:58:25 +0300	[thread overview]
Message-ID: <20190819065827.26921-13-noaos@mellanox.com> (raw)
In-Reply-To: <20190819065827.26921-1-noaos@mellanox.com>

Add a module-specific load_tests method in __init__.py. It currently
locates all existing tests under its directory (files should start
with 'test_') and runs them without any parameters. In order to run a
test with a specific set of parameters, user can add the relevant
lines in __init__.py (example provided in the file).

Signed-off-by: Noa Osherovich <noaos@mellanox.com>
---
 run_tests.py      | 20 +++++++-------------
 tests/__init__.py | 17 +++++++++++++++++
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index dbee92d942bd..4f6b212dab9f 100644
--- a/run_tests.py
+++ b/run_tests.py
@@ -1,22 +1,16 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2018, Mellanox Technologies. All rights reserved.  See COPYING file
-import unittest,os,os.path,fnmatch
-import tests
 
+import unittest
 
+
+# Run from /usr/share/doc/rdma-core-<version>
 def test_all():
-    # FIXME: This implementation is for older Python versions, will
-    # be replaced with discover()
-    return test_suite
+    module = __import__('tests')
+    loader = unittest.TestLoader()
+    suite = loader.loadTestsFromModule(module)
+    return suite
 
-module = __import__("tests")
-fns = [os.path.splitext(I)[0] for I in fnmatch.filter(os.listdir(module.__path__[0]),"*.py")]
-fns.remove("__init__")
-for I in fns:
-    __import__("tests." + I)
-test_suite = unittest.TestSuite(unittest.defaultTestLoader.loadTestsFromNames(fns,module))
 
 if __name__ == '__main__':
     unittest.main(defaultTest="test_all")
-
-
diff --git a/tests/__init__.py b/tests/__init__.py
index e69de29bb2d1..7a2efdfb6e6b 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
+# Copyright (c) 2019 Mellanox Technologies, Inc . All rights reserved. See COPYING file
+
+import unittest
+
+
+def load_tests(loader, standard_tests, pattern):
+    loader = unittest.TestLoader()
+    suite = loader.discover('tests')
+    return suite
+#   To run only some test cases / parametrized tests:
+#   1. Add RDMATestCase to the imports:
+#    from tests.base import RDMATestCase
+#   2. Replace the current TestSuite with a customized one and add tests to it
+#      (parameters are optional)
+#    suite = unittest.TestSuite()
+#    suite.addTest(RDMATestCase.parametrize(YourTestCase, dev_name='rocep0s8f0', ...))
-- 
2.21.0


  parent reply	other threads:[~2019-08-19  6:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19  6:58 [PATCH rdma-core 00/14] rdma-core tests infrastructure Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 01/14] pyverbs/tests: Rename base class Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 02/14] pyverbs: Move tests to a stand-alone directory Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 03/14] build: Add pyverbs-based test to the build Noa Osherovich
2019-08-19 13:50   ` Jason Gunthorpe
2019-08-20 13:00     ` Noa Osherovich
2019-08-22 16:18       ` Leon Romanovsky
2019-08-22 16:52         ` Jason Gunthorpe
2019-09-01 13:30           ` Noa Osherovich
2019-09-09 10:29             ` Leon Romanovsky
2019-09-09 10:39               ` Noa Osherovich
2019-09-09 11:26                 ` Leon Romanovsky
2019-09-09 11:30                   ` Noa Osherovich
2019-09-09 11:38                     ` Leon Romanovsky
2019-09-09 11:34                   ` Leon Romanovsky
2019-08-19  6:58 ` [PATCH rdma-core 04/14] tests: BaseResources Class Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 05/14] tests: RDMATestCase Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 06/14] tests: TrafficResources class Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 07/14] tests: RCResources and UDResources classes Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 08/14] tests: ODP requires decorator Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 09/14] tests: Add traffic helper methods Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 10/14] tests: Add ODP RC test Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 11/14] tests: Add ODP UD test Noa Osherovich
2019-08-19  6:58 ` Noa Osherovich [this message]
2019-08-19  6:58 ` [PATCH rdma-core 13/14] Documentation: Add background for rdma-core tests Noa Osherovich
2019-08-19  6:58 ` [PATCH rdma-core 14/14] tests: Unify API tests' output Noa Osherovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190819065827.26921-13-noaos@mellanox.com \
    --to=noaos@mellanox.com \
    --cc=dledford@redhat.com \
    --cc=jgg@mellanox.com \
    --cc=leonro@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.