haystack/test/test_lazy_imports.py
Sara Calla 61866ba9aa
chore: make the lazy import error message clearer (#9667)
* made the lazy import error message clearer

* add header
2025-07-31 16:10:14 +02:00

23 lines
746 B
Python

# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
import pytest
from haystack.lazy_imports import DEFAULT_IMPORT_ERROR_MSG, LazyImport
class TestLazyImport:
def test_import_error_is_suppressed_and_deferred(self):
with LazyImport() as lazy_import:
import a_module
assert lazy_import._deferred is not None
exc_value, message = lazy_import._deferred
assert isinstance(exc_value, ImportError)
expected_message = (
"Haystack failed to import the optional dependency 'a_module'. Try 'pip install a_module'. "
"Original error: No module named 'a_module'"
)
assert expected_message in message