From 7bd1c465c949c988c90f446f4fb6d0e459109bd4 Mon Sep 17 00:00:00 2001 From: Rafael Sarmiento Date: Mon, 3 Dec 2018 15:43:32 +0100 Subject: [PATCH 1/6] handle bad test --- reframe/core/decorators.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/reframe/core/decorators.py b/reframe/core/decorators.py index e1f50e4b52..8442f348b0 100644 --- a/reframe/core/decorators.py +++ b/reframe/core/decorators.py @@ -7,6 +7,7 @@ import collections import inspect +import traceback import reframe from reframe.core.exceptions import ReframeSyntaxError @@ -26,12 +27,18 @@ def _instantiate(): except AttributeError: mod.__rfm_skip_tests = set() - if isinstance(args, collections.Sequence): - ret.append(cls(*args)) - elif isinstance(args, collections.Mapping): - ret.append(cls(**args)) - elif args is None: - ret.append(cls()) + try: + if isinstance(args, collections.Sequence): + ret.append(cls(*args)) + elif isinstance(args, collections.Mapping): + ret.append(cls(**args)) + elif args is None: + ret.append(cls()) + except Exception as e: + getlogger().info('skipping test defined in class %s due ' + 'to errors. Please check file %s' % + (cls.__name__, inspect.getfile(cls))) + getlogger().debug(traceback.format_exc()) return ret From 13970b31bf3522506cf0cfdbc892edc8b0721636 Mon Sep 17 00:00:00 2001 From: Rafael Sarmiento Date: Mon, 10 Dec 2018 13:31:39 +0100 Subject: [PATCH 2/6] fix comments --- reframe/core/decorators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/reframe/core/decorators.py b/reframe/core/decorators.py index 8442f348b0..1160708afe 100644 --- a/reframe/core/decorators.py +++ b/reframe/core/decorators.py @@ -35,9 +35,9 @@ def _instantiate(): elif args is None: ret.append(cls()) except Exception as e: - getlogger().info('skipping test defined in class %s due ' - 'to errors. Please check file %s' % - (cls.__name__, inspect.getfile(cls))) + getlogger().error('%s:%s: skipping due to errors; check log' + 'file for more information.' % + (inspect.getfile(cls), cls.__name__)) getlogger().debug(traceback.format_exc()) return ret From bf1361edb188ce89d4c6e7d7a995039ff8fb397c Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Sun, 20 Jan 2019 01:17:53 +0100 Subject: [PATCH 3/6] Improve message and enhance implementation --- reframe/core/decorators.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/reframe/core/decorators.py b/reframe/core/decorators.py index 1160708afe..f6a9c96c88 100644 --- a/reframe/core/decorators.py +++ b/reframe/core/decorators.py @@ -7,17 +7,26 @@ import collections import inspect +import sys import traceback import reframe -from reframe.core.exceptions import ReframeSyntaxError +from reframe.core.exceptions import ReframeSyntaxError, user_frame from reframe.core.logging import getlogger from reframe.core.pipeline import RegressionTest from reframe.utility.versioning import Version, VersionValidator def _register_test(cls, args=None): - def _instantiate(): + def _instantiate(cls, args): + if isinstance(args, collections.Sequence): + return cls(*args) + elif isinstance(args, collections.Mapping): + return cls(**args) + elif args is None: + return cls() + + def _instantiate_all(): ret = [] for cls, args in mod.__rfm_test_registry: try: @@ -28,23 +37,19 @@ def _instantiate(): mod.__rfm_skip_tests = set() try: - if isinstance(args, collections.Sequence): - ret.append(cls(*args)) - elif isinstance(args, collections.Mapping): - ret.append(cls(**args)) - elif args is None: - ret.append(cls()) + _instantiate(cls, args) except Exception as e: - getlogger().error('%s:%s: skipping due to errors; check log' - 'file for more information.' % - (inspect.getfile(cls), cls.__name__)) - getlogger().debug(traceback.format_exc()) + frame = user_frame(sys.exc_info()[2]) + msg = 'skipping test due to errors: %s\n' % cls.__name__ + msg += ' %s:%s' % (frame.filename, frame.lineno) + getlogger().warning(msg) + getlogger().verbose(traceback.format_exc()) return ret mod = inspect.getmodule(cls) if not hasattr(mod, '_rfm_gettests'): - mod._rfm_gettests = _instantiate + mod._rfm_gettests = _instantiate_all try: mod.__rfm_test_registry.append((cls, args)) From 7f1ac39012e857850c1a635e82f7843e58b92cb8 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Thu, 24 Jan 2019 11:21:17 +0100 Subject: [PATCH 4/6] Emit hint to use `-v` for details on test errors --- reframe/core/decorators.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reframe/core/decorators.py b/reframe/core/decorators.py index f6a9c96c88..fb64b1b959 100644 --- a/reframe/core/decorators.py +++ b/reframe/core/decorators.py @@ -40,8 +40,9 @@ def _instantiate_all(): _instantiate(cls, args) except Exception as e: frame = user_frame(sys.exc_info()[2]) - msg = 'skipping test due to errors: %s\n' % cls.__name__ - msg += ' %s:%s' % (frame.filename, frame.lineno) + msg = "skipping test due to errors: %s: " % cls.__name__ + msg += "use `-v' for more information\n" + msg += " FILE: %s:%s" % (frame.filename, frame.lineno) getlogger().warning(msg) getlogger().verbose(traceback.format_exc()) From 7c051cf93a173aa4caf6475a80c15e024fcb2a9c Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Thu, 24 Jan 2019 21:37:49 +0100 Subject: [PATCH 5/6] Fix unit tests --- reframe/core/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reframe/core/decorators.py b/reframe/core/decorators.py index fb64b1b959..d5b6dd96de 100644 --- a/reframe/core/decorators.py +++ b/reframe/core/decorators.py @@ -37,7 +37,7 @@ def _instantiate_all(): mod.__rfm_skip_tests = set() try: - _instantiate(cls, args) + ret.append(_instantiate(cls, args)) except Exception as e: frame = user_frame(sys.exc_info()[2]) msg = "skipping test due to errors: %s: " % cls.__name__ From fcb30fc846843b99108ce78d4636361177fe0012 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Fri, 25 Jan 2019 00:01:36 +0100 Subject: [PATCH 6/6] Add unit test for loading bad test in __init__() --- unittests/resources/checks_unlisted/bad_init_check.py | 7 +++++++ unittests/test_loader.py | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 unittests/resources/checks_unlisted/bad_init_check.py diff --git a/unittests/resources/checks_unlisted/bad_init_check.py b/unittests/resources/checks_unlisted/bad_init_check.py new file mode 100644 index 0000000000..811d9d077b --- /dev/null +++ b/unittests/resources/checks_unlisted/bad_init_check.py @@ -0,0 +1,7 @@ +import reframe as rfm + + +@rfm.simple_test +class BadInitTest(rfm.RegressionTest): + def __init__(self): + foo diff --git a/unittests/test_loader.py b/unittests/test_loader.py index 138a2e1313..d4656e2216 100644 --- a/unittests/test_loader.py +++ b/unittests/test_loader.py @@ -63,3 +63,8 @@ def test_load_bad_required_version(self): with self.assertRaises(ValueError): self.loader.load_from_file('unittests/resources/checks_unlisted/' 'no_required_version.py') + + def test_load_bad_init(self): + tests = self.loader.load_from_file( + 'unittests/resources/checks_unlisted/bad_init_check.py') + self.assertEqual(0, len(tests))