diff --git a/rq/scripts/__init__.py b/rq/scripts/__init__.py index d02f26d..94441ab 100644 --- a/rq/scripts/__init__.py +++ b/rq/scripts/__init__.py @@ -1,3 +1,4 @@ +import importlib import redis from rq import use_connection @@ -19,7 +20,7 @@ def add_standard_arguments(parser): def read_config_file(module): """Reads all UPPERCASE variables defined in the given module file.""" - settings = __import__(module, [], [], [], -1) + settings = importlib.import_module(module) return dict([(k, v) for k, v in settings.__dict__.items() if k.upper() == k]) diff --git a/tests/dummy_settings.py b/tests/dummy_settings.py new file mode 100644 index 0000000..1404250 --- /dev/null +++ b/tests/dummy_settings.py @@ -0,0 +1 @@ +REDIS_HOST = "testhost.example.com" diff --git a/tests/test_scripts.py b/tests/test_scripts.py new file mode 100644 index 0000000..de266ef --- /dev/null +++ b/tests/test_scripts.py @@ -0,0 +1,8 @@ +from unittest import TestCase +from rq.scripts import read_config_file + +class TestScripts(TestCase): + def test_config_file(self): + settings = read_config_file("tests.dummy_settings") + self.assertIn("REDIS_HOST", settings) + self.assertEqual(settings['REDIS_HOST'], "testhost.example.com")