[elbe-devel] [PATCH] test: make ElbeTestCase.params implementation clearer

Torben Hohn torben.hohn at linutronix.de
Wed Jul 22 17:38:21 CEST 2020


that self.params is a single parameter is confusing.

Add ElbeTestCase.__init__() that saves the methodname parameter.
Then implement parameterize() that constructs another instance,
with self.param setup to the parameter.

Then make ElbeTestSuite() use that.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/commands/test.py      | 16 +++++++++++-----
 elbepack/tests/test_doctest.py |  6 +++---
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/elbepack/commands/test.py b/elbepack/commands/test.py
index 31f1ae2dd..161008576 100644
--- a/elbepack/commands/test.py
+++ b/elbepack/commands/test.py
@@ -25,12 +25,20 @@ class ElbeTestCase(unittest.TestCase):
 
     level = ElbeTestLevel.BASE
 
+    def __init__(self, methodName='runTest', param=None):
+        self.methodName = methodName
+        self.param = param
+        super().__init__(methodName)
+
     def __str__(self):
         name = super(ElbeTestCase, self).__str__()
-        if hasattr(self, "params"):
-            return "%s : params=%s" % (name, getattr(self, "params"))
+        if self.param:
+            return "%s : param=%s" % (name, self.param)
         return name
 
+    def parameterize(self, param):
+        return self.__class__(methodName=self.methodName, param=param)
+
 # TODO:py3 - Remove useless object inheritance
 # pylint: disable=useless-object-inheritance
 class ElbeTestSuite(object):
@@ -50,9 +58,7 @@ class ElbeTestSuite(object):
                 continue
 
             for param in test.params:
-                clone        = copy.deepcopy(test)
-                clone.params = param
-                self.tests.append(clone)
+                self.tests.append(test.parameterize(param))
 
     def __iter__(self):
         for test in self.tests:
diff --git a/elbepack/tests/test_doctest.py b/elbepack/tests/test_doctest.py
index a19a57452..a908f9e8c 100644
--- a/elbepack/tests/test_doctest.py
+++ b/elbepack/tests/test_doctest.py
@@ -19,14 +19,14 @@ class ElbeDocTest(ElbeTestCase):
 
         self.kwargs = {}
 
-        if self.params is filesystem:
+        if self.param is filesystem:
             self.kwargs["extraglobs"] = {"this":filesystem.TmpdirFilesystem()}
 
     def tearDown(self):
 
-        if self.params is filesystem:
+        if self.param is filesystem:
             self.kwargs["extraglobs"]["this"].delete()
 
     def test_doctest(self):
-        fail, _ = doctest.testmod(self.params, **self.kwargs)
+        fail, _ = doctest.testmod(self.param, **self.kwargs)
         self.assertEqual(fail, 0)
-- 
2.20.1



More information about the elbe-devel mailing list