From 2a198d59fe5eb7db9e45de8288644aad66704909 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 18 Jul 2014 13:33:51 +0100 Subject: [PATCH] Unittest - Add mechanism to skip task and taskd tests * When testing multiple clients vs server versions, repeating client tests is unnecessary. By setting the env variables TASKW_SKIP and TASKD_SKIP it will now be possible to skip all task (client only) and taskd (client + server) tests, respectively. --- test/basetest/__init__.py | 2 +- test/basetest/testing.py | 19 ++++++++++++++++++- test/basetest/utils.py | 4 ++++ test/template.t | 5 ++--- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/test/basetest/__init__.py b/test/basetest/__init__.py index 5933ba5c8..4dd647039 100644 --- a/test/basetest/__init__.py +++ b/test/basetest/__init__.py @@ -2,6 +2,6 @@ from .task import Task from .taskd import Taskd -from .testing import TestCase +from .testing import TestCase, ServerTestCase # vim: ai sts=4 et sw=4 diff --git a/test/basetest/testing.py b/test/basetest/testing.py index e90f81b46..f8ef42a6f 100644 --- a/test/basetest/testing.py +++ b/test/basetest/testing.py @@ -2,9 +2,11 @@ import unittest import sys +from .utils import TASKW_SKIP, TASKD_SKIP +from .taskd import Taskd -class TestCase(unittest.TestCase): +class BaseTestCase(unittest.TestCase): def diag(self, out): sys.stdout.write("# --- diag start ---\n") for line in out.split("\n"): @@ -12,4 +14,19 @@ class TestCase(unittest.TestCase): sys.stdout.write("# --- diag end ---\n") +@unittest.skipIf(TASKW_SKIP, "TASKW_SKIP set, skipping task tests.") +class TestCase(BaseTestCase): + """Automatically skips tests if TASKW_SKIP is present in the environment + """ + pass + + +@unittest.skipIf(TASKD_SKIP, "TASKD_SKIP set, skipping taskd tests.") +@unittest.skipIf(Taskd.not_available(), "Taskd binary not available") +class ServerTestCase(BaseTestCase): + """Automatically skips tests if TASKD_SKIP is present in the environment + """ + pass + + # vim: ai sts=4 et sw=4 diff --git a/test/basetest/utils.py b/test/basetest/utils.py index ecd1c2257..bf68e60ec 100644 --- a/test/basetest/utils.py +++ b/test/basetest/utils.py @@ -13,6 +13,10 @@ from .exceptions import CommandError USED_PORTS = set() ON_POSIX = 'posix' in sys.builtin_module_names +# Environment flags to control skipping of task and taskd tests +TASKW_SKIP = os.environ.get("TASKW_SKIP", False) +TASKD_SKIP = os.environ.get("TASKD_SKIP", False) + def wait_process(proc, timeout=1): """Wait for process to finish diff --git a/test/template.t b/test/template.t index cb081eaf9..e3db8b8a8 100755 --- a/test/template.t +++ b/test/template.t @@ -8,7 +8,7 @@ from datetime import datetime # Ensure python finds the local simpletap module sys.path.append(os.path.dirname(os.path.abspath(__file__))) -from basetest import Task, Taskd, TestCase +from basetest import Task, TestCase, Taskd, ServerTestCase class TestBugNumber(TestCase): @@ -53,8 +53,7 @@ class TestBugNumber(TestCase): """Executed once after all tests in the class""" -@unittest.skipIf(Taskd.not_available(), "Taskd binary not available") -class ServerTestCase(TestCase): +class ServerTestBugNumber(ServerTestCase): @classmethod def setUpClass(cls): cls.taskd = Taskd()