[elbe-devel] [PATCH v3 3/3] tests test_doctest: Make doctests use ElbeTestCase

Olivier Dion dion at linutronix.de
Fri Jun 26 17:15:50 CEST 2020


To test more module for doctesting, one has to add the module to the
'params' attribute.

If a module needs a certain context, do just like the 'filesystem'
module does.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/filesystem.py         |  5 ++++-
 elbepack/tests/test_doctest.py | 25 ++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index 6c22368a..51697907 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -502,7 +502,10 @@ class TmpdirFilesystem (Filesystem):
         if self.debug:
             print('leaving TmpdirFilesystem in "%s"' % self.path)
         else:
-            shutil.rmtree(self.path, True)
+            self.delete()
+
+    def delete(self):
+        shutil.rmtree(self.path, True)
 
 
 class ImgMountFilesystem(Filesystem):
diff --git a/elbepack/tests/test_doctest.py b/elbepack/tests/test_doctest.py
index 9fd47d64..a19a5745 100644
--- a/elbepack/tests/test_doctest.py
+++ b/elbepack/tests/test_doctest.py
@@ -9,9 +9,24 @@ import unittest
 import elbepack.shellhelper as shellhelper
 import elbepack.filesystem as filesystem
 
-def load_tests(loader, tests, ignore):
-    tests.addTests(doctest.DocTestSuite(shellhelper))
-    fs = filesystem.TmpdirFilesystem()
-    tests.addTests(doctest.DocTestSuite(filesystem, extraglobs={"this":fs}))
+from elbepack.commands.test import ElbeTestCase
 
-    return tests
+class ElbeDocTest(ElbeTestCase):
+
+    params = [shellhelper, filesystem]
+
+    def setUp(self):
+
+        self.kwargs = {}
+
+        if self.params is filesystem:
+            self.kwargs["extraglobs"] = {"this":filesystem.TmpdirFilesystem()}
+
+    def tearDown(self):
+
+        if self.params is filesystem:
+            self.kwargs["extraglobs"]["this"].delete()
+
+    def test_doctest(self):
+        fail, _ = doctest.testmod(self.params, **self.kwargs)
+        self.assertEqual(fail, 0)
-- 
2.27.0




More information about the elbe-devel mailing list