[TIP] parametrize a pytest finalizer
Carl Meyer
carl at oddbird.net
Thu Apr 10 09:21:41 PDT 2014
Hi Chris,
On 04/10/2014 08:49 AM, Pella,Chris wrote:
> That works well, although I don’t understand why. I haven’t used lambdas
> before, but the signature is the same as for a normal function. I guess
> the anonymity makes pytest treat it differently.
Lambdas aren't treated any differently by py.test; it is the signature
that is different:
lambda: cleanup("Doing cleanup!")
The function cleanup takes a single argument, but the lambda function
created here takes no arguments, then calls cleanup() with one argument.
The equivalent using a named function instead of a lambda:
def wrapper():
cleanup("Doing cleanup!")
Carl
More information about the testing-in-python
mailing list