qubes/tests: Show errors while loading external tests
Now failure to load external tests shows in which entry point the error happened and a useful traceback. The traceback extends from the "try" statement down to the actual error line, but it does not include the frames above, ie. from the invocation to the load_tests routine. This is a limitation of Python itself and usually not a problem.
This commit is contained in:
parent
1ff1ca37a1
commit
c899d1f960
@ -22,6 +22,7 @@
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import sys
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import qubes.tests
|
import qubes.tests
|
||||||
import qubes.vm.appvm
|
import qubes.vm.appvm
|
||||||
@ -71,8 +72,17 @@ class ExtraTestCase(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
|
|
||||||
def load_tests(loader, tests, pattern):
|
def load_tests(loader, tests, pattern):
|
||||||
for entry in pkg_resources.iter_entry_points('qubes.tests.extra'):
|
for entry in pkg_resources.iter_entry_points('qubes.tests.extra'):
|
||||||
for test_case in entry.load()():
|
try:
|
||||||
tests.addTests(loader.loadTestsFromTestCase(test_case))
|
for test_case in entry.load()():
|
||||||
|
tests.addTests(loader.loadTestsFromTestCase(test_case))
|
||||||
|
except Exception as err: # pylint: disable=broad-except
|
||||||
|
tb = sys.exc_info()[2]
|
||||||
|
def runTest(self):
|
||||||
|
raise err, None, tb
|
||||||
|
ExtraLoadFailure = type('ExtraLoadFailure',
|
||||||
|
(qubes.tests.QubesTestCase,),
|
||||||
|
{entry.name: runTest})
|
||||||
|
tests.addTest(ExtraLoadFailure(entry.name))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
app = qubes.Qubes()
|
app = qubes.Qubes()
|
||||||
@ -83,15 +93,24 @@ def load_tests(loader, tests, pattern):
|
|||||||
|
|
||||||
for entry in pkg_resources.iter_entry_points(
|
for entry in pkg_resources.iter_entry_points(
|
||||||
'qubes.tests.extra.for_template'):
|
'qubes.tests.extra.for_template'):
|
||||||
for test_case in entry.load()():
|
try:
|
||||||
for template in templates:
|
for test_case in entry.load()():
|
||||||
tests.addTests(loader.loadTestsFromTestCase(
|
for template in templates:
|
||||||
type(
|
tests.addTests(loader.loadTestsFromTestCase(
|
||||||
'{}_{}_{}'.format(
|
type(
|
||||||
entry.name, test_case.__name__, template),
|
'{}_{}_{}'.format(
|
||||||
(test_case,),
|
entry.name, test_case.__name__, template),
|
||||||
{'template': template}
|
(test_case,),
|
||||||
)
|
{'template': template}
|
||||||
))
|
)
|
||||||
|
))
|
||||||
|
except Exception as err: # pylint: disable=broad-except
|
||||||
|
tb = sys.exc_info()[2]
|
||||||
|
def runTest(self):
|
||||||
|
raise err, None, tb
|
||||||
|
ExtraForTemplateLoadFailure = type('ExtraForTemplateLoadFailure',
|
||||||
|
(qubes.tests.QubesTestCase,),
|
||||||
|
{entry.name: runTest})
|
||||||
|
tests.addTest(ExtraLoadFailure(entry.name))
|
||||||
|
|
||||||
return tests
|
return tests
|
||||||
|
Loading…
Reference in New Issue
Block a user