From d88ff935d02ec82ed024bb3acf7e35e6fba035af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 2 May 2016 00:19:18 +0200 Subject: [PATCH] tests: adjust 'extra' tests API to better design from core3 Do not force inheritance of ExtraTestMixin and QubesTestCase. Instead provide 'qubes.tests.extra.ExtraTestCase' for external tests. This makes the API less "magic", easier to understand and apply static analysis tools on it. QubesOS/qubes-issues#1800 --- tests/__init__.py | 2 +- tests/extra.py | 15 ++++----------- tests/run.py | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index e30200fa..c9d26b49 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -175,7 +175,7 @@ class QubesTestCase(unittest.TestCase): def __str__(self): return '{}/{}/{}'.format( - '.'.join(self.__class__.__module__.split('.')[2:]), + self.__class__.__module__, self.__class__.__name__, self._testMethodName) diff --git a/tests/extra.py b/tests/extra.py index 91efade8..c46a8a81 100644 --- a/tests/extra.py +++ b/tests/extra.py @@ -27,12 +27,12 @@ import qubes.tests import qubes.qubes -class ExtraTestMixin(qubes.tests.SystemTestsMixin): +class ExtraTestCase(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): template = None def setUp(self): - super(ExtraTestMixin, self).setUp() + super(ExtraTestCase, self).setUp() self.qc.unlock_db() def create_vms(self, names): @@ -74,13 +74,7 @@ class ExtraTestMixin(qubes.tests.SystemTestsMixin): def load_tests(loader, tests, pattern): for entry in pkg_resources.iter_entry_points('qubes.tests.extra'): for test_case in entry.load()(): - tests.addTests(loader.loadTestsFromTestCase( - type( - entry.name + '_' + test_case.__name__, - (test_case, ExtraTestMixin, qubes.tests.QubesTestCase), - {} - ) - )) + tests.addTests(loader.loadTestsFromTestCase(test_case)) try: qc = qubes.qubes.QubesVmCollection() @@ -100,8 +94,7 @@ def load_tests(loader, tests, pattern): type( '{}_{}_{}'.format( entry.name, test_case.__name__, template), - (test_case, ExtraTestMixin, - qubes.tests.QubesTestCase), + (test_case,), {'template': template} ) )) diff --git a/tests/run.py b/tests/run.py index dae4c0b7..78441eb3 100755 --- a/tests/run.py +++ b/tests/run.py @@ -314,7 +314,7 @@ def main(): for name in args.names: suite.addTests( [test for test in list_test_cases(alltests) - if (str(test)+'/').startswith(name.replace('.', '/')+'/')]) + if str(test).startswith(name)]) else: suite.addTests(loader.loadTestsFromName('qubes.tests'))