pipefunc.testing module#
Testing utilities for the pipefunc package.
- pipefunc.testing.patch(pipeline, func_name)[source]#
Patch a function within a Pipeline for testing purposes.
This function provides a context manager to temporarily replace the function of a specified
PipeFuncinstance within the pipeline.- Parameters:
pipeline (
Pipeline) – The Pipeline instance to be patched.func_name (
str) – The name of the function to be patched. This can be either a simple function name or a fully qualified name including the module path. If a dot is present in func_name, the function will attempt to match the full module path and function name. Otherwise, it will use only the function name.
- Yields:
mock – A MagicMock object that can be used to set return values or side effects.
- Raises:
ValueError – If no function with the given name is found in the pipeline.
- Return type:
Examples
>>> @pipefunc(output_name="c") ... def f() -> Any: ... raise ValueError("test")
>>> pipeline = Pipeline([f])
>>> with patch(pipeline, "f") as mock: ... mock.return_value = 1 ... print(pipeline("c")) # Prints 1