<@ULVA73B9P> I am testing controlflow by running p...
# ask-marvin
c
@Marvin I am testing controlflow by running pytest tests. These tests expect to have a LLM API Key and I don't have one. How can I change these tests to mock LLM interaction and pass these tests?
m
To mock LLM interactions in your pytest tests for ControlFlow, you can use Python's
unittest.mock
module. This allows you to simulate the behavior of the LLM API without needing an actual API key. Here's a basic outline of how you can achieve this: 1. Identify the LLM function or method: Determine which function or method in your code interacts with the LLM. This might be a method that sends a request to the LLM API. 2. Mock the LLM interaction: Use
unittest.mock.patch
to replace the LLM function or method with a mock object that returns a predefined response. Here's a simple example:
Copy code
python
from unittest.mock import patch

# Assuming 'your_module.llm_interaction' is the function that calls the LLM API
@patch('your_module.llm_interaction')
def test_your_function(mock_llm_interaction):
    # Define what the mock should return
    mock_llm_interaction.return_value = "Mocked LLM response"

    # Call the function that uses the LLM
    result = your_function()

    # Assert the expected behavior
    assert result == "Expected result based on mocked LLM response"
This approach allows you to run your tests without an actual LLM API key, by simulating the API's responses. For more detailed settings and configurations related to LLM in ControlFlow, you might find the ControlFlow settings guide useful.
n
hi @Chandra Ilindra it probably just wants an OPENAI_API_KEY but i will say I'd check out https://github.com/PrefectHQ/marvin where we 've ported the controlflow functionality
c
Yeah, I want to run the tests without OPENAI_API_KEY. I will check out marvin repo, thanks for the pointer.
n
just fyi the tests do need to make API calls to an LLM provider, so you need to auth somehow