Skip to content

Add utilily pytest fixtures for IntentGuard and IntentGuardOptions #29

@ELC

Description

@ELC

As this tools integrates with pytest, it would be great to have the following fixtures made available automatically:

import intentguard as ig

import pytest

@pytest.fixture
def guard_options() -> ig.IntentGuardOptions:
    return ig.IntentGuardOptions(
        num_evaluations=1,
        temperature=0.4,
    )


@pytest.fixture
def guard(guard_options: ig.IntentGuardOptions) -> ig.IntentGuard:
    return ig.IntentGuard(guard_options)

This will allow to refactor tests from

import intentguard as ig

def test_intention() -> None:
    guard = ig.IntentGuard()
    guard.assert_code(intention, {"module": imported_module })

To:

import intentguard as ig

def test_intention(guard: ig.IntentGuard) -> None:
    guard.assert_code(intention, {"module": imported_module })

The user could do this anyway for their codebase, but as other tools like VCR, request-mocks, pytest-subtest, syrupy do, I believe it is convient and enhances the developer experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions