test_invoke_with_model_override() — langchain Function Reference
Architecture documentation for the test_invoke_with_model_override() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 06a19980_86e1_7aed_70bd_c218e2725ba7["test_invoke_with_model_override()"] 971e928f_9c9b_ce7a_b93d_e762f2f5aa54["ChatModelIntegrationTests"] 06a19980_86e1_7aed_70bd_c218e2725ba7 -->|defined in| 971e928f_9c9b_ce7a_b93d_e762f2f5aa54 style 06a19980_86e1_7aed_70bd_c218e2725ba7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 910–950
def test_invoke_with_model_override(self, model: BaseChatModel) -> None:
"""Test that model name can be overridden at invoke time via kwargs.
This enables dynamic model selection without creating new instances,
which is useful for fallback strategies, A/B testing, or cost optimization.
Test is skipped if `supports_model_override` is `False`.
??? question "Troubleshooting"
If this test fails, ensure that your `_generate` method passes
`**kwargs` through to the API request payload in a way that allows
the `model` parameter to be overridden.
For example:
```python
def _get_request_payload(self, ..., **kwargs) -> dict:
return {
"model": self.model,
...
**kwargs, # kwargs should come last to allow overrides
}
```
"""
if not self.supports_model_override:
pytest.skip("Model override not supported.")
override_model = self.model_override_value
if not override_model:
pytest.skip("model_override_value not specified.")
result = model.invoke("Hello", model=override_model)
assert result is not None
assert isinstance(result, AIMessage)
# Verify the overridden model was used
model_name = result.response_metadata.get("model_name")
assert model_name is not None, "model_name not found in response_metadata"
assert override_model in model_name, (
f"Expected model '{override_model}' but got '{model_name}'"
)
Domain
Subdomains
Source
Frequently Asked Questions
What does test_invoke_with_model_override() do?
test_invoke_with_model_override() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py.
Where is test_invoke_with_model_override() defined?
test_invoke_with_model_override() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 910.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free