pytest-check
pytest-check copied to clipboard
Is early error checking possible?
Is there now a surefire way to check for errors even before the test ends?
I can do something like this, but it seems that this is not quite the intended scenario for using pytest-check
import pytest_check as check
from pytest_check.check_methods import get_failures
def test_some():
check.equal(1, 2, msg="Numbers are not equal")
check.equal(2, 1, msg="Numbers are not equal")
assert not get_failures()
raise NotImplementedError
Failing early isn't something I considered before, but not a bad idea.
Maybe something like an assert_no_failures()
function.
Would that work for your use cases?
exactly what is needed!
This is already doable in 2 ways, see below.
I sometimes use the first (get_failures()
). Haven't used th second one as I just use assert
instead.
- Call
get_failures()
import pytest_check as check from pytest_check.check_methods import get_failures def test_something(): do_something() check.equal(...) check.equal(...) assert not get_failures() # Test case ends here if any `check` above failed check.equal(...)
- Do
set_stop_on_fail(True)
before the checks.
geeezz I now read the whole first comment where it already states the use of get_failures()
, sorry.
That said, I think its use quite reasonable. Bummer that we need an extra import though.
check.any_failures()
is now implemented, so a workable workaround is:
assert not check.any_failures()