pytest: fail but continue checking (built-in subtests, tested)
A failing assert ends the current test, so later checks never run. On pytest 9.0+, request the built-in subtests fixture and wrap each check in with subtests.test(key=...):; every check runs, each failure is reported as SUBFAILED, and the test as a whole fails.
pytest already continues with the next test after a failure (unless you pass -x). What stops is the rest of the failing test: the first failing assert raises and later checks in the same function never run. Since pytest 9.0 the built-in subtests fixture lets one test keep going and report every failed check. Measured with pytest 9.1.1 on Python 3.13.5, no plugins.
1. Plain asserts vs the subtests fixture
$ cat test_sub.py
def test_plain_asserts():
data = {"a": 1, "b": 2, "c": 3}
assert data["a"] == 1
assert data["b"] == 20 # stops here
assert data["c"] == 30 # never checked
def test_with_subtests(subtests):
data = {"a": 1, "b": 2, "c": 3}
for key, want in [("a", 1), ("b", 20), ("c", 30)]:
with subtests.test(msg="check", key=key):
assert data[key] == want
$ pytest --version
pytest 9.1.1
$ pytest -q -p no:cacheprovider --tb=line test_sub.py; echo "exit $?"
FuuuF [100%]
=================================== FAILURES ===================================
E assert 2 == 20
/tmp/sb388/test_sub.py:4: assert 2 == 20
E assert 2 == 20
/tmp/sb388/test_sub.py:11: assert 2 == 20
E assert 3 == 30
/tmp/sb388/test_sub.py:11: assert 3 == 30
contains 2 failed subtests
contains 2 failed subtests
=========================== short test summary info ============================
FAILED test_sub.py::test_plain_asserts - assert 2 == 20
SUBFAILED[check] (key='b') test_sub.py::test_with_subtests - assert 2 == 20
SUBFAILED[check] (key='c') test_sub.py::test_with_subtests - assert 3 == 30
FAILED test_sub.py::test_with_subtests - contains 2 failed subtests
4 failed, 1 subtests passed in 0.01s
exit 1
test_plain_asserts reports only assert 2 == 20; the wrong value for "c" is never checked. test_with_subtests runs all three checks and reports both failures as SUBFAILED[check] (key='b') and (key='c'), then marks the test itself FAILED with "contains 2 failed subtests". The summary line counts subtests separately ("1 subtests passed"), and the exit code is still 1.
2. Notes
subtestsneeds no install on pytest 9.0 or newer; on older versions it came from the separatepytest-subtestsplugin.- The keyword arguments to
subtests.test(...)(herekey=) appear in the report, so put the loop variable there. - If the checks are independent cases,
@pytest.mark.parametrizeis often clearer: each case becomes its own test. Use subtests when the cases share expensive setup inside one test. - To stop the whole run at the first failure instead, see pytest fail fast.
Related: pytest parametrize: expect an error, pytest.raises: get the error message, pytest.fail with a message vs xfail.
Frequently asked questions
How do I make pytest continue after a failed assert?
Use the subtests fixture (built into pytest 9.0+): wrap each check in with subtests.test(...): and the test keeps running, reporting every failed check.
Does pytest stop after the first failing test?
No. Other tests still run; only the failing test function stops at its first failing assert. Use -x to stop the whole run.
Do I need pytest-subtests?
Not on pytest 9.0 or newer; the subtests fixture is built in. Older versions needed the pytest-subtests plugin.
Written with AI assistance. Measured on 2026-10-23 with pytest 9.1.1 on Python 3.13.5 in a clean virtualenv without plugins. Each block was run verbatim and the output pasted unedited. PlainHeaders is our extension; pytest is free.