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): |
| 8 | class_found = None |
| 9 | for name, obj in inspect.getmembers(module): |
| 10 | if inspect.isclass(obj) and issubclass(obj, unittest.TestCase): |
| 11 | if obj.__name__.endswith('exchange'): |
| 12 | class_found = obj |
| 13 | break |
| 14 | else: |
| 15 | class_found = obj |
| 16 | |
| 17 | assert_not_equal(class_found, None) |
| 18 | try: |
| 19 | module_name = module.__name__.split('.')[-1] |
| 20 | except: |
| 21 | module_name = module.__name__ |
| 22 | |
| 23 | cfg = '{}.json'.format(module_name) |
| 24 | module_config = os.path.join(os.path.dirname(module.__file__), cfg) |
| 25 | if os.access(module_config, os.F_OK): |
| 26 | with open(module_config) as f: |
| 27 | json_data = json.load(f) |
| 28 | for k, v in json_data.iteritems(): |
| 29 | setattr(class_found, k, v) |