[Asterisk-code-review] Added Debug Message for Test Objects Configured as Base Type (testsuite[master])

Ashley Sanders asteriskteam at digium.com
Mon Dec 7 19:08:36 CST 2015


Ashley Sanders has uploaded a new change for review.

  https://gerrit.asterisk.org/1775

Change subject: Added Debug Message for Test Objects Configured as Base Type
......................................................................

Added Debug Message for Test Objects Configured as Base Type

When configuring a test module, it is especially easy to
misconfigure the requested test-object as a type of
'test_case.TestCase' instead of 'test_case.TestCaseModule'.
The significant difference between these two types is
'test_case.TestCase' is the base type of the Python test
modules, while 'test_case.TestCaseModule' is a derived type
of 'test_case.TestCase', and serves as the base type for
pluggable modules.

Unfortunately, because 'test_case.TestCaseModule' is a
derived type of 'test_case.TestCase', misconfiguring the
test-object to use the base class, results in the module
successfully loading and appearing to execute succesfully in
a mechanical sense, but fails unexpectedly and without any
meaningful feedback.

This patch attempts to help the developer of test modules
such that if the base type is used, a debug message is piped
to the testsuite log, indicating a possible misconfiguration
of the test-object type in the test-config.yaml.

ASTERISK-25557 Reported By: Ashley Sanders

Change-Id: I8a16d2f43ae5944680ba393f39bdb80f5df79e07
---
M lib/python/asterisk/test_runner.py
1 file changed, 15 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/75/1775/1

diff --git a/lib/python/asterisk/test_runner.py b/lib/python/asterisk/test_runner.py
index 640ccd3..2f6405f 100755
--- a/lib/python/asterisk/test_runner.py
+++ b/lib/python/asterisk/test_runner.py
@@ -179,7 +179,11 @@
         LOGGER.error("No module specified: %s" % module_name)
         return None
 
-    module = __import__(module_name)
+    try:
+        module = __import__(module_name)
+    except ImportError as e:
+        LOGGER.error("ImportError: %s" % e)
+        raise
     for comp in parts[1:]:
         module = getattr(module, comp)
     return module
@@ -316,6 +320,16 @@
     if test_object is None:
         return 1
 
+    from test_case import TestCase
+
+    if type(test_object) == TestCase:
+        LOGGER.debug(
+            "**Possible Test Misconfiguration: The test has been configured "
+            "to instantiate a type of 'test_case.TestCase' as its "
+            "test-object; however, this type is the base type for the Python "
+            "tests and not a pluggable module. Did you mean to use "
+            "'test_case.TestCaseModule?'")
+
     # Load other modules that may be specified
     load_test_modules(test_config, test_object, ast_version)
 

-- 
To view, visit https://gerrit.asterisk.org/1775
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8a16d2f43ae5944680ba393f39bdb80f5df79e07
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Ashley Sanders <asanders at digium.com>



More information about the asterisk-code-review mailing list