Skip to content

Commit 9dc3655

Browse files
authored
Merge pull request #623 from rsarm/internals/bad-check-handling
[bugfix] Improve handling of bad tests to avoid frontend crashing
2 parents f349a3e + fcb30fc commit 9dc3655

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

reframe/core/decorators.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,26 @@
77

88
import collections
99
import inspect
10+
import sys
11+
import traceback
1012

1113
import reframe
12-
from reframe.core.exceptions import ReframeSyntaxError
14+
from reframe.core.exceptions import ReframeSyntaxError, user_frame
1315
from reframe.core.logging import getlogger
1416
from reframe.core.pipeline import RegressionTest
1517
from reframe.utility.versioning import Version, VersionValidator
1618

1719

1820
def _register_test(cls, args=None):
19-
def _instantiate():
21+
def _instantiate(cls, args):
22+
if isinstance(args, collections.Sequence):
23+
return cls(*args)
24+
elif isinstance(args, collections.Mapping):
25+
return cls(**args)
26+
elif args is None:
27+
return cls()
28+
29+
def _instantiate_all():
2030
ret = []
2131
for cls, args in mod.__rfm_test_registry:
2232
try:
@@ -26,18 +36,21 @@ def _instantiate():
2636
except AttributeError:
2737
mod.__rfm_skip_tests = set()
2838

29-
if isinstance(args, collections.Sequence):
30-
ret.append(cls(*args))
31-
elif isinstance(args, collections.Mapping):
32-
ret.append(cls(**args))
33-
elif args is None:
34-
ret.append(cls())
39+
try:
40+
ret.append(_instantiate(cls, args))
41+
except Exception as e:
42+
frame = user_frame(sys.exc_info()[2])
43+
msg = "skipping test due to errors: %s: " % cls.__name__
44+
msg += "use `-v' for more information\n"
45+
msg += " FILE: %s:%s" % (frame.filename, frame.lineno)
46+
getlogger().warning(msg)
47+
getlogger().verbose(traceback.format_exc())
3548

3649
return ret
3750

3851
mod = inspect.getmodule(cls)
3952
if not hasattr(mod, '_rfm_gettests'):
40-
mod._rfm_gettests = _instantiate
53+
mod._rfm_gettests = _instantiate_all
4154

4255
try:
4356
mod.__rfm_test_registry.append((cls, args))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import reframe as rfm
2+
3+
4+
@rfm.simple_test
5+
class BadInitTest(rfm.RegressionTest):
6+
def __init__(self):
7+
foo

unittests/test_loader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ def test_load_bad_required_version(self):
6363
with self.assertRaises(ValueError):
6464
self.loader.load_from_file('unittests/resources/checks_unlisted/'
6565
'no_required_version.py')
66+
67+
def test_load_bad_init(self):
68+
tests = self.loader.load_from_file(
69+
'unittests/resources/checks_unlisted/bad_init_check.py')
70+
self.assertEqual(0, len(tests))

0 commit comments

Comments
 (0)