Skip to content

Commit

Permalink
Update test to skip when optional dependencies are not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
dagardner-nv committed Dec 17, 2024
1 parent b35d861 commit 9d5e6a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/morpheus_llm/llm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/morpheus_llm/llm/test_agents_simple_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9d5e6a3

Please sign in to comment.