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

Olivier Dion dion at linutronix.de
Mon Jun 22 19:15:32 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/tests/test_doctest.py | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/elbepack/tests/test_doctest.py b/elbepack/tests/test_doctest.py
index 9fd47d64..65f3ec80 100644
--- a/elbepack/tests/test_doctest.py
+++ b/elbepack/tests/test_doctest.py
@@ -9,9 +9,27 @@ 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):
+
+        # FIXME - Apparently this is not enough for Python to actually
+        # delete this temporary filesystem.  Maybe add something like
+        # filesystem.force_delete().
+        if self.params is filesystem:
+            del self.kwargs["extraglobs"]["this"]
+
+    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