Unfortunately, there is often no way to doctest such functions directly, and for some re-writing them as lambda functions is impossible or reduces readability.
CC: @zimmermann6
Component: doctest coverage
Issue created by migration from https://trac.sagemath.org/ticket/4323