diff --git a/satpy/readers/__init__.py b/satpy/readers/__init__.py index 3a05bd0c16..ef0d8713c3 100644 --- a/satpy/readers/__init__.py +++ b/satpy/readers/__init__.py @@ -563,16 +563,9 @@ def load_readers(filenames=None, reader=None, reader_kwargs=None): else: readers_files = remaining_filenames - try: - reader_instance = load_reader( - reader_configs, - **reader_kwargs[None if reader is None else reader[idx]]) - except (KeyError, IOError) as err: - LOG.info("Cannot use %s", str(reader_configs)) - LOG.debug(str(err)) + reader_instance = _get_reader_instance(reader, reader_configs, idx, **reader_kwargs) + if reader_instance is None: continue - except yaml.YAMLError as err: - _log_yaml_error(reader_configs, err) if not readers_files: # we weren't given any files for this reader @@ -592,6 +585,21 @@ def load_readers(filenames=None, reader=None, reader_kwargs=None): return reader_instances +def _get_reader_instance(reader, reader_configs, idx, **reader_kwargs): + reader_instance = None + try: + reader_instance = load_reader( + reader_configs, + **reader_kwargs[None if reader is None else reader[idx]]) + except (KeyError, IOError) as err: + LOG.info("Cannot use %s", str(reader_configs)) + LOG.debug(str(err)) + except yaml.YAMLError as err: + _log_yaml_error(reader_configs, err) + + return reader_instance + + def _log_yaml_error(reader_configs, err): LOG.error("Problem with %s", str(reader_configs)) LOG.error(str(err)) diff --git a/satpy/tests/test_readers.py b/satpy/tests/test_readers.py index a3aef9114e..bff268fdd2 100644 --- a/satpy/tests/test_readers.py +++ b/satpy/tests/test_readers.py @@ -458,7 +458,7 @@ def test_yaml_error_message(self, load_reader): load_reader.side_effect = yaml.YAMLError(error_message) with self._caplog.at_level(logging.ERROR): - with pytest.raises(UnboundLocalError): + with pytest.raises(match=ValueError): _ = load_readers(filenames=filenames, reader="avhrr_l1b_eps") assert error_message in self._caplog.text