test_retrying() — langchain Function Reference
Architecture documentation for the test_retrying() function in test_runnable.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 4becb306_21ba_dac9_68f8_27e88f689364["test_retrying()"] 26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"] 4becb306_21ba_dac9_68f8_27e88f689364 -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5 593bb72a_4695_6c93_b95c_e277aca006ae["batch()"] 4becb306_21ba_dac9_68f8_27e88f689364 -->|calls| 593bb72a_4695_6c93_b95c_e277aca006ae fb618d44_c03b_ea8b_385b_2278dfb173d4["invoke()"] 4becb306_21ba_dac9_68f8_27e88f689364 -->|calls| fb618d44_c03b_ea8b_385b_2278dfb173d4 style 4becb306_21ba_dac9_68f8_27e88f689364 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/runnables/test_runnable.py lines 3865–3927
def test_retrying(mocker: MockerFixture) -> None:
def _lambda(x: int) -> int:
if x == 1:
msg = "x is 1"
raise ValueError(msg)
if x == 2:
msg = "x is 2"
raise RuntimeError(msg)
return x
lambda_mock = mocker.Mock(side_effect=_lambda)
runnable = RunnableLambda(lambda_mock)
with pytest.raises(ValueError, match="x is 1"):
runnable.invoke(1)
assert lambda_mock.call_count == 1
lambda_mock.reset_mock()
with pytest.raises(ValueError, match="x is 1"):
runnable.with_retry(
stop_after_attempt=2,
retry_if_exception_type=(ValueError,),
exponential_jitter_params={"initial": 0.1},
).invoke(1)
assert lambda_mock.call_count == 2 # retried
lambda_mock.reset_mock()
with pytest.raises(RuntimeError):
runnable.with_retry(
stop_after_attempt=2,
wait_exponential_jitter=False,
retry_if_exception_type=(ValueError,),
).invoke(2)
assert lambda_mock.call_count == 1 # did not retry
lambda_mock.reset_mock()
with pytest.raises(ValueError, match="x is 1"):
runnable.with_retry(
stop_after_attempt=2,
wait_exponential_jitter=False,
retry_if_exception_type=(ValueError,),
).batch([1, 2, 0])
# 3rd input isn't retried because it succeeded
assert lambda_mock.call_count == 3 + 2
lambda_mock.reset_mock()
output = runnable.with_retry(
stop_after_attempt=2,
wait_exponential_jitter=False,
retry_if_exception_type=(ValueError,),
).batch([1, 2, 0], return_exceptions=True)
# 3rd input isn't retried because it succeeded
assert lambda_mock.call_count == 3 + 2
assert len(output) == 3
assert isinstance(output[0], ValueError)
assert isinstance(output[1], RuntimeError)
assert output[2] == 0
lambda_mock.reset_mock()
Domain
Subdomains
Source
Frequently Asked Questions
What does test_retrying() do?
test_retrying() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_retrying() defined?
test_retrying() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 3865.
What does test_retrying() call?
test_retrying() calls 2 function(s): batch, invoke.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free