parametrize_from_file.cast
- parametrize_from_file.cast(**funcs)
Return a schema function that will apply functions to the given test parameters.
- Parameters:
funcs (dict) – Keyword arguments where each key is the name of a parameter and each value is either a function or a list of functions to transform that parameter with. When lists of functions are given, the functions will be applied in order, with the return value of each becoming the input to the next.
Any keys that are missing will be silently ignored; this makes it easier to provide default values with
defaults
. Note that if you usedefaults
beforecast
, then the default values will be transformed as if they had been read from the parameter file. In contrast, if you usecast
beforedefaults
, then the default values will be used directly.See the Python snippets and Optional parameters tutorials for some good in-context examples.
Example
>>> f = cast(a=int) >>> f({'a': '1'}) {'a': 1} >>> f({}) {} >>> from math import sqrt >>> g = cast(a=[int, sqrt]) >>> g({'a': '4'}) {'a': 2.0}