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:
parent
edd473c4be
commit
d88ff935d0
@ -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)
|
||||
|
||||
|
@ -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}
|
||||
)
|
||||
))
|
||||
|
@ -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'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user