From 9d5e6a3bf3447ffe4fba89de59c9397cf2b8b514 Mon Sep 17 00:00:00 2001 From: David Gardner Date: Tue, 17 Dec 2024 08:37:05 -0800 Subject: [PATCH] Update test to skip when optional dependencies are not installed --- tests/conftest.py | 10 ++++++++++ tests/morpheus_llm/llm/conftest.py | 8 ++++++++ tests/morpheus_llm/llm/test_agents_simple_pipe.py | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 093eada5c1..5babac6e1f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1125,6 +1125,16 @@ def langchain_community_fixture(fail_missing: bool): fail_missing=fail_missing) +@pytest.fixture(name="langchain_openai", scope='session') +def langchain_community_fixture(fail_missing: bool): + """ + Fixture to ensure langchain_openai is installed + """ + yield import_or_skip("langchain_openai", + reason=OPT_DEP_SKIP_REASON.format(package="langchain_openai"), + fail_missing=fail_missing) + + @pytest.fixture(name="langchain_nvidia_ai_endpoints", scope='session') def langchain_nvidia_ai_endpoints_fixture(fail_missing: bool): """ diff --git a/tests/morpheus_llm/llm/conftest.py b/tests/morpheus_llm/llm/conftest.py index 427b8b46c7..8d196720aa 100644 --- a/tests/morpheus_llm/llm/conftest.py +++ b/tests/morpheus_llm/llm/conftest.py @@ -61,6 +61,14 @@ def langchain_community_fixture(langchain_community: types.ModuleType): yield langchain_community +@pytest.fixture(name="langchain_openai", scope='session', autouse=True) +def langchain_community_fixture(langchain_openai: types.ModuleType): + """ + Fixture to ensure langchain_openai is installed + """ + yield langchain_openai + + @pytest.fixture(name="langchain_nvidia_ai_endpoints", scope='session', autouse=True) def langchain_nvidia_ai_endpoints_fixture(langchain_nvidia_ai_endpoints: types.ModuleType): """ diff --git a/tests/morpheus_llm/llm/test_agents_simple_pipe.py b/tests/morpheus_llm/llm/test_agents_simple_pipe.py index d219a9780e..8aa9e0d0e1 100644 --- a/tests/morpheus_llm/llm/test_agents_simple_pipe.py +++ b/tests/morpheus_llm/llm/test_agents_simple_pipe.py @@ -127,7 +127,7 @@ def test_agents_simple_pipe_integration_openai(config: Config, questions: list[s assert float(response_match.group(1)) >= 3.7 -@pytest.mark.usefixtures("openai", "restore_environ") +@pytest.mark.usefixtures("langchain_community", "langchain_openai", "openai", "restore_environ") @mock.patch("langchain_community.utilities.serpapi.SerpAPIWrapper.aresults") @mock.patch("langchain_openai.OpenAI._agenerate", autospec=True) # autospec is needed as langchain will inspect the function