nemoguardrails.testing.fixtures
Pytest fixtures exposing the public testing surface.
To opt in, add the following to your project’s conftest.py::
pytest_plugins = [“nemoguardrails.testing.fixtures”]
The fixtures below provide reasonable defaults that cover the most common
testing patterns: a scriptable :class:FakeLLMModel and a :class:TestChat
factory that wires the fake model into an :class:LLMRails app.
Module Contents
Functions
API
Return a :class:FakeLLMModel with a single "Hello!" response.
Override the responses by overriding this fixture in your own conftest, or
instantiate :class:FakeLLMModel directly when you need custom behaviour::
from nemoguardrails.testing import FakeLLMModel
llm = FakeLLMModel(responses=[“My scripted answer”])
Return a factory for building :class:FakeLLMModel instances.
Useful when a single test needs more than one fake model, or when the set of responses is computed dynamically::
def test_two_calls(make_fake_llm): llm_one = make_fake_llm(responses=[“one”]) llm_two = make_fake_llm(responses=[“two”])
Return a factory that builds :class:TestChat instances bound to a
fake LLM.
Example::
def test_greeting(make_test_chat): config = RailsConfig.from_path(”./examples/bots/abc”) chat = make_test_chat(config, llm_completions=[“Hi there!”]) chat.user(“hi”) chat.bot(“Hi there!”)