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
This commit is contained in:
Marek Marczykowski-Górecki 2016-05-02 00:19:18 +02:00
parent edd473c4be
commit d88ff935d0
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 6 additions and 13 deletions

View File

@ -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)

View File

@ -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}
)
))

View File

@ -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'))