> This page is for version v0.25.0.
> For other versions, use one of these documentation indexes:
> - Latest (default): https://docs.nvidia.com/nemo/guardrails/latest/llms.txt
> - v0.25.0: https://docs.nvidia.com/nemo/guardrails/v0.25.0/llms.txt
> - v0.24.1: https://docs.nvidia.com/nemo/guardrails/v0.24.1/llms.txt
> - v0.24.0: https://docs.nvidia.com/nemo/guardrails/v0.24.0/llms.txt
> - v0.23.0: https://docs.nvidia.com/nemo/guardrails/v0.23.0/llms.txt
> - v0.22.0: https://docs.nvidia.com/nemo/guardrails/v0.22.0/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.

# nemoguardrails.testing.fixtures

Pytest fixtures exposing the public testing surface.

To opt in, add the following to your project's `conftest.py`:

```python
pytest_plugins = ["nemoguardrails.testing.fixtures"]
```

The fixtures below provide reasonable defaults that cover the most common
testing patterns: a scriptable `FakeLLMModel` and a `TestChat`
factory that wires the fake model into an `LLMRails` app.

## Module Contents

### Functions

| Name                                                                | Description                                                  |
| ------------------------------------------------------------------- | ------------------------------------------------------------ |
| [`fake_llm`](#nemoguardrails-testing-fixtures-fake_llm)             | Return a `FakeLLMModel` with a single `"Hello!"` response.   |
| [`make_fake_llm`](#nemoguardrails-testing-fixtures-make_fake_llm)   | Return a factory for building `FakeLLMModel` instances.      |
| [`make_test_chat`](#nemoguardrails-testing-fixtures-make_test_chat) | Return a factory that builds `TestChat` instances bound to a |

### API

```python
nemoguardrails.testing.fixtures.fake_llm() -> nemoguardrails.testing.fake_model.FakeLLMModel
```

Return a `FakeLLMModel` with a single `"Hello!"` response.

Override the responses by overriding this fixture in your own conftest, or
instantiate `FakeLLMModel` directly when you need custom behaviour:

```python
from nemoguardrails.testing import FakeLLMModel

llm = FakeLLMModel(responses=["My scripted answer"])
```

```python
nemoguardrails.testing.fixtures.make_fake_llm() -> typing.Callable[..., nemoguardrails.testing.fake_model.FakeLLMModel]
```

Return a factory for building `FakeLLMModel` instances.

Useful when a single test needs more than one fake model, or when the set
of responses is computed dynamically:

```python
def test_two_calls(make_fake_llm):
    llm_one = make_fake_llm(responses=["one"])
    llm_two = make_fake_llm(responses=["two"])
```

```python
nemoguardrails.testing.fixtures.make_test_chat() -> typing.Callable[..., nemoguardrails.testing.chat_harness.TestChat]
```

Return a factory that builds `TestChat` instances bound to a
fake LLM.

Example:

```python
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!")
```