---
question: Can I pytest a workflow without an engine?
kind: task
via_web: na
via_cli: available
via_python: available
via_api: na
via_config: na
ref_cli: uv run pytest
ref_python: run(parameters)
prereq: You need a workflow class with `run` implemented. [Create a workflow](/capabilities/build/agents/creating-a-workflow) first.
next:
  - /capabilities/build/workflows/expose-as-a-tool
  - /capabilities/build/agents/test-an-agent
  - /capabilities/build/modules/test-a-module
---

# Test a workflow

A workflow test builds the class and awaits `run` with a parameters instance, in `<Name>Workflow_test.py` next to the file. The module's discovery skips `_test.py` files, and `abi new workflow` writes that test with the class. The test needs no engine and no broker. Chatting with the live model is a different test: [Test an agent](/capabilities/build/agents/test-an-agent).

## Web UI

Not applicable. Nexus runs no tests. To try the workflow through an agent, see [Test an agent](/capabilities/build/agents/test-an-agent).

## CLI

### Run the test file

From the project root:

```bash
uv run pytest src/reports/workflows/CustomersWorkflow_test.py
```

`uv run pytest src/reports` runs every test of the module. Write the tests as in the [Python steps](/capabilities/build/workflows/test-a-workflow?via=python).

## Python

### Call `run` with parameters

`run` is `async`: run it with `asyncio.run`. This is the test `abi new workflow Greeting` writes next to the class it scaffolds, `GreetingWorkflow`, which echoes a message and reads no service:

```python title="src/reports/workflows/GreetingWorkflow_test.py"
import asyncio

from .GreetingWorkflow import (
    GreetingWorkflow,
    GreetingWorkflowConfiguration,
    GreetingWorkflowParameters,
)


def test_the_workflow_runs() -> None:
    workflow = GreetingWorkflow(GreetingWorkflowConfiguration())

    result = asyncio.run(workflow.run(GreetingWorkflowParameters(message="hi")))

    assert result == {"message": "hi"}
```

### Mock what it calls

The next two steps test another class, `CustomersWorkflow` from [Create a workflow](/capabilities/build/agents/creating-a-workflow?via=python), in its own `CustomersWorkflow_test.py`. It reads the triple store through its module, so the test hands it a stand-in module whose `query` is an `AsyncMock`. The test then needs no network and no data:

```python title="src/reports/workflows/CustomersWorkflow_test.py"
import asyncio
from unittest.mock import AsyncMock, MagicMock

from .CustomersWorkflow import (
    CustomersWorkflow,
    CustomersWorkflowConfiguration,
    CustomersWorkflowParameters,
)


def test_the_workflow_reads_the_graph() -> None:
    module = MagicMock()
    module.engine.services.triple_store.query = AsyncMock(return_value=[("Acme",)])
    workflow = CustomersWorkflow(CustomersWorkflowConfiguration(), module)

    result = asyncio.run(workflow.run(CustomersWorkflowParameters(entity_id="42")))

    assert result == {"entity_id": "42", "labels": ["Acme"]}
    module.engine.services.triple_store.query.assert_awaited_once()
```

Mock an integration the same way: hand the class a stand-in for the client it calls.

### Check its name and its tool

In the same `CustomersWorkflow_test.py`:

```python title="src/reports/workflows/CustomersWorkflow_test.py"
def test_the_workflow_is_named_after_its_class() -> None:
    assert CustomersWorkflow.slug() == "customers_workflow"


def test_the_tool_describes_the_intent() -> None:
    assert "Summarize" in CustomersWorkflow.description()
```

The slug is the name other modules start it by (`workflow.customers_workflow`), so the first test catches a rename. The description is the class docstring, which an agent reads to pick the tool.

## REST API

Not applicable. The API starts a workflow but has no test runner. To check a start by hand, call it as in [Run a workflow](/capabilities/build/workflows/run-a-workflow?via=api).

## Config

Not applicable. Tests are Python files, not `config.yaml` entries.

## What to test

- **One test per intent.** Each parameters combination that changes the result.
- **Validation.** A bad parameters instance raises a Pydantic `ValidationError` before `run` starts.
- **Name and description.** `slug()` and `description()`: callers start the workflow by the one, and the model picks the tool by the other.
- **Durable runs.** Starting `workflow.<slug>` needs a broker and a running module. Test `run` here, and the durable start by hand in System › Jobs ([Run a workflow](/capabilities/build/workflows/run-a-workflow?via=web)).
