Support for per test case configuration.
The test case needs to import setup_module from CordTestConfig.
See the igmp test case example.
The test case config file is a json file that should be named as:
$testmodulename.json
Eg: if test module name is igmpTest.py, the config file should be named as:
igmpTest.json
The default test configuration variables should be placed under the class variables.
The cord tester classes should subclass unittest.TestCase and should be ideally suffixed with _exchange.
The import of setup_module function from CordTestConfig for a test case would automatically
assign/overwrite the configuration parameters (json key,value pairs) for the class to be accessed by the test cases.
Change-Id: Iae6f993a149b4547388b86245663f24bb0e2b86b
diff --git a/src/test/utils/CordTestConfig.py b/src/test/utils/CordTestConfig.py
new file mode 100644
index 0000000..0e369d9
--- /dev/null
+++ b/src/test/utils/CordTestConfig.py
@@ -0,0 +1,29 @@
+import inspect
+import unittest
+import json
+import os
+from nose.tools import assert_not_equal
+
+def setup_module(module):
+ class_found = None
+ for name, obj in inspect.getmembers(module):
+ if inspect.isclass(obj) and issubclass(obj, unittest.TestCase):
+ if obj.__name__.endswith('exchange'):
+ class_found = obj
+ break
+ else:
+ class_found = obj
+
+ assert_not_equal(class_found, None)
+ try:
+ module_name = module.__name__.split('.')[-1]
+ except:
+ module_name = module.__name__
+
+ cfg = '{}.json'.format(module_name)
+ module_config = os.path.join(os.path.dirname(module.__file__), cfg)
+ if os.access(module_config, os.F_OK):
+ with open(module_config) as f:
+ json_data = json.load(f)
+ for k, v in json_data.iteritems():
+ setattr(class_found, k, v)