Skip to content

Commit 4b52416

Browse files
author
basti
committed
Make config import more reliable.
1 parent 5519b74 commit 4b52416

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/__init__.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11

2+
import imp
3+
import os.path
4+
25
from amazonproduct import HOSTS
36

4-
import os.path
57
_here = os.path.abspath(os.path.dirname(__file__))
68

9+
10+
try:
11+
fp, path, desc = imp.find_module('config', [_here])
12+
_config = imp.load_module('config', fp, _here, desc)
13+
except ImportError:
14+
_config = None
15+
716
#: Directory containing XML responses for API versions (one directory for each
817
#: API version)
918
XML_TEST_DIR = _here
@@ -23,11 +32,11 @@ def get_config_value(key, default=None):
2332
(in that order).
2433
"""
2534
try:
26-
config = __import__('config')
27-
return getattr(config, key)
28-
except (ImportError, AttributeError):
35+
return getattr(_config, key)
36+
except AttributeError:
2937
return os.environ.get(key, default)
3038

3139
AWS_KEY = get_config_value('AWS_KEY', '')
3240
SECRET_KEY = get_config_value('SECRET_KEY', '')
3341
OVERWRITE_TESTS = get_config_value('OVERWRITE_TESTS', '')
42+

0 commit comments

Comments
 (0)