From 4b5b5d910b43882cb58e66edf003dbf1d0b76ba8 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Tue, 22 Jan 2019 10:30:55 +0100 Subject: [PATCH] dist/pythonlibs: provide unittest TestCase wrapper for testrunner I had this idea when implementing #10382 and #10392 as I introduced a very similar structure to python's standard unittests in those and it could also reduce some code duplication between those two tests. --- dist/pythonlibs/testrunner/__init__.py | 1 + dist/pythonlibs/testrunner/unittest.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 dist/pythonlibs/testrunner/unittest.py diff --git a/dist/pythonlibs/testrunner/__init__.py b/dist/pythonlibs/testrunner/__init__.py index 667777a5cb..9ff2d9de3b 100755 --- a/dist/pythonlibs/testrunner/__init__.py +++ b/dist/pythonlibs/testrunner/__init__.py @@ -13,6 +13,7 @@ from traceback import print_tb import pexpect from .spawn import find_exc_origin, setup_child, teardown_child +from .unittest import PexpectTestCase # noqa, F401 expose to users def run(testfunc, timeout=10, echo=True, traceback=False): diff --git a/dist/pythonlibs/testrunner/unittest.py b/dist/pythonlibs/testrunner/unittest.py new file mode 100644 index 0000000000..4ee7b25959 --- /dev/null +++ b/dist/pythonlibs/testrunner/unittest.py @@ -0,0 +1,23 @@ +# Copyright (C) 2018-19 Freie Universität Berlin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import unittest +from testrunner import setup_child, teardown_child + + +class PexpectTestCase(unittest.TestCase): + TIMEOUT = 10 + LOGFILE = None + + """A unittest TestCase providing a pexpect spawn object to it's tests + """ + @classmethod + def setUpClass(cls): + cls.spawn = setup_child(cls.TIMEOUT, logfile=cls.LOGFILE) + + @classmethod + def tearDownClass(cls): + teardown_child(cls.spawn)