From dd13dfe82bd6ae0d0d15235e8505c0ea905dd841 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Wed, 3 Oct 2012 12:31:19 -0300 Subject: [PATCH] Raise error when settings module is missing. Previously, it failed silently if an ImportError was caught when trying to import the scrapy settings module. This not only happened when the scrapy settings module itself was missing, but also when it tried to import a missing module, which made the whole thing a bad idea. A side effect of this change (not required, but for simplification) is that we no longer support the default "scrapy_settings" name for the scrapy settings module, but this was never used afaik. --- scrapy/utils/project.py | 6 +++--- scrapy/utils/testproc.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/scrapy/utils/project.py b/scrapy/utils/project.py index a64fcda4f..a2edb7b08 100644 --- a/scrapy/utils/project.py +++ b/scrapy/utils/project.py @@ -51,10 +51,10 @@ def get_project_settings(): if ENVVAR not in os.environ: project = os.environ.get('SCRAPY_PROJECT', 'default') init_env(project) - settings_module_path = os.environ.get(ENVVAR, 'scrapy_settings') - try: + settings_module_path = os.environ.get(ENVVAR) + if settings_module_path: settings_module = __import__(settings_module_path, {}, {}, ['']) - except ImportError: + else: settings_module = None settings = CrawlerSettings(settings_module) diff --git a/scrapy/utils/testproc.py b/scrapy/utils/testproc.py index 22239d82f..cba3b4346 100644 --- a/scrapy/utils/testproc.py +++ b/scrapy/utils/testproc.py @@ -9,9 +9,10 @@ class ProcessTest(object): prefix = [sys.executable, '-m', 'scrapy.cmdline'] cwd = os.getcwd() # trial chdirs to temp dir - def execute(self, args, check_code=True, settings='missing'): + def execute(self, args, check_code=True, settings=None): env = os.environ.copy() - env['SCRAPY_SETTINGS_MODULE'] = settings + if settings is not None: + env['SCRAPY_SETTINGS_MODULE'] = settings cmd = self.prefix + [self.command] + list(args) pp = TestProcessProtocol() pp.deferred.addBoth(self._process_finished, cmd, check_code)