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

Torben Hohn torben.hohn at linutronix.de
Wed Jun 24 17:15:48 CEST 2020


On Mon, Jun 22, 2020 at 01:15:32PM -0400, Olivier Dion wrote:
> 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"]

maybe try https://mg.pov.lt/objgraph/ ?

probably something is still holding a reference on it.

> +
> +    def test_doctest(self):
> +        fail, _ = doctest.testmod(self.params, **self.kwargs)
> +        self.assertEqual(fail, 0)
> -- 
> 2.27.0
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



More information about the elbe-devel mailing list