pytest-check icon indicating copy to clipboard operation
pytest-check copied to clipboard

How can I determine immediately after a check if it passed or failed?

Open ALPA-Industry-and-Technology opened this issue 3 months ago • 2 comments

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?

okken avatar Sep 18 '25 22:09 okken

I guess I don't mention that in the docs. That'd be good to do.

okken avatar Sep 18 '25 22:09 okken