Home / Function/ test_retry_with_failure_then_success() — langchain Function Reference

test_retry_with_failure_then_success() — langchain Function Reference

Architecture documentation for the test_retry_with_failure_then_success() function in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  cdb31ede_55f5_8c3c_becd_a04745a31beb["test_retry_with_failure_then_success()"]
  aaa4b344_20ed_7fa3_4067_f8f05affc01f["test_chat_models.py"]
  cdb31ede_55f5_8c3c_becd_a04745a31beb -->|defined in| aaa4b344_20ed_7fa3_4067_f8f05affc01f
  style cdb31ede_55f5_8c3c_becd_a04745a31beb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/mistralai/tests/unit_tests/test_chat_models.py lines 331–371

def test_retry_with_failure_then_success() -> None:
    """Test retry mechanism works correctly when fiest request fails, second succeed."""
    # Create a real ChatMistralAI instance
    chat = ChatMistralAI(max_retries=3)

    # Set up the actual retry mechanism (not just mocking it)
    # We'll track how many times the function is called
    call_count = 0

    def mock_post(*args: Any, **kwargs: Any) -> MagicMock:
        nonlocal call_count
        call_count += 1

        if call_count == 1:
            msg = "Connection error"
            raise httpx.RequestError(msg, request=MagicMock())

        mock_response = MagicMock()
        mock_response.status_code = 200
        mock_response.json.return_value = {
            "choices": [
                {
                    "message": {
                        "role": "assistant",
                        "content": "Hello!",
                    },
                    "finish_reason": "stop",
                }
            ],
            "usage": {
                "prompt_tokens": 1,
                "completion_tokens": 1,
                "total_tokens": 2,
            },
        }
        return mock_response

    with patch.object(chat.client, "post", side_effect=mock_post):
        result = chat.invoke("Hello")
        assert result.content == "Hello!"
        assert call_count == 2, f"Expected 2 calls, but got {call_count}"

Domain

Subdomains

Frequently Asked Questions

What does test_retry_with_failure_then_success() do?
test_retry_with_failure_then_success() is a function in the langchain codebase, defined in libs/partners/mistralai/tests/unit_tests/test_chat_models.py.
Where is test_retry_with_failure_then_success() defined?
test_retry_with_failure_then_success() is defined in libs/partners/mistralai/tests/unit_tests/test_chat_models.py at line 331.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free