How can I determine immediately after a check if it passed or failed?
Hi,
I’m using pytest-check and I would like to know if there is a way to determine right after calling a check (e.g. check.equal(a, b)) whether that check succeeded or failed, so that I can react in my test logic immediately.
check.any_failures() only gives me a global status for the whole test, but I need to know the result of each individual check right after it runs.
Is there a recommended way to achieve this? Or would I need to wrap the check functions myself (e.g. with check.fail() and a custom return value)?
Thanks!
With best regards Alex
All of the check methods, like check.equal(), return True or False.
See check_functions.py in the source.
So, you can just do something like:
if check.equal(a, b):
... # they are equal
else
... # they are not equal, and a failure was registered by the check method
Does this work for you?
I guess I don't mention that in the docs. That'd be good to do.