A R Karthick | 861da96 | 2017-02-08 16:21:36 -0800 | [diff] [blame] | 1 | import inspect |
| 2 | import unittest |
| 3 | import json |
| 4 | import os |
| 5 | from nose.tools import assert_not_equal |
| 6 | |
| 7 | def setup_module(module): |
A.R Karthick | 9904482 | 2017-02-09 14:04:20 -0800 | [diff] [blame] | 8 | class_test = None |
A R Karthick | 861da96 | 2017-02-08 16:21:36 -0800 | [diff] [blame] | 9 | for name, obj in inspect.getmembers(module): |
| 10 | if inspect.isclass(obj) and issubclass(obj, unittest.TestCase): |
| 11 | if obj.__name__.endswith('exchange'): |
A.R Karthick | 9904482 | 2017-02-09 14:04:20 -0800 | [diff] [blame] | 12 | class_test = obj |
A R Karthick | 861da96 | 2017-02-08 16:21:36 -0800 | [diff] [blame] | 13 | break |
| 14 | else: |
A.R Karthick | 9904482 | 2017-02-09 14:04:20 -0800 | [diff] [blame] | 15 | class_test = obj |
A R Karthick | 861da96 | 2017-02-08 16:21:36 -0800 | [diff] [blame] | 16 | |
A.R Karthick | 9904482 | 2017-02-09 14:04:20 -0800 | [diff] [blame] | 17 | assert_not_equal(class_test, None) |
| 18 | module_name = module.__name__.split('.')[-1] |
A R Karthick | 861da96 | 2017-02-08 16:21:36 -0800 | [diff] [blame] | 19 | cfg = '{}.json'.format(module_name) |
| 20 | module_config = os.path.join(os.path.dirname(module.__file__), cfg) |
| 21 | if os.access(module_config, os.F_OK): |
| 22 | with open(module_config) as f: |
| 23 | json_data = json.load(f) |
| 24 | for k, v in json_data.iteritems(): |
A.R Karthick | 9904482 | 2017-02-09 14:04:20 -0800 | [diff] [blame] | 25 | setattr(class_test, k, v) |