Skip to Content
Judgment Labs

TestEnvironmentsFactory

Create and read test environments. Access via client.test_environments.

A test environment is the world a test case runs in: canned tool results and starting data, stored as an immutable name@version. A case names one in its metadata.environment; client.test_runs.start then returns the definition for your test runner to apply.

Test environments must be enabled for your organization.

client.test_environments.create(
    name="ticket-service-down",
    definition={
        "tools": {
            "create_ticket": [{"return": {"error": "service unavailable"}}],
            "lookup_order": [
                {"match": {"order_id": "A1"}, "return": {"status": "shipped"}}
            ],
        },
        "seed": {"orders": [{"order_id": "A1"}]},
    },
)
client.test_suites.add_cases(
    test_suite_id,
    [
        {
            "input": {"prompt": "Where is order A1?"},
            "metadata": {"environment": "ticket-service-down@1"},
        }
    ],
)

create()

Create a test environment as its version 1.

name takes lowercase letters, digits, - and _. Do not store credentials in definition.

def create(name, definition, description=None) -> Dict[str, Any]:

Parameters

Prop

Type

Returns

Dict[str, Any]


add_version()

Add the next version. Earlier versions never change.

def add_version(name, definition, description=None) -> Dict[str, Any]:

Parameters

Prop

Type

Returns

Dict[str, Any]


list()

List the latest version of each environment, without definitions.

def list() -> Dict[str, Any]:

Returns

Dict[str, Any]


get()

Get one version of an environment with its definition.

def get(name, version) -> Dict[str, Any]:

Parameters

Prop

Type

Returns

Dict[str, Any]

On this page