Description
Consider adding a flag on the SubTests
class which would allow the same behavior as --exitfirst
, but scoped within a test scope.
Proposed usage may look something like:
def test_foo(subtests):
subtests.stop_upon_failure = True # new flag
with subtests.test("sub1"):
assert False, "This sub test failed"
with subtests.test("sub2"): # This would not get executed
...
Use cases:
-
Using
subtests
to distinguish steps within a workflow, somewhat analogous to what happens with gherkin style frameworks like pytest-bdd. There may be no reason to continue with subsequent steps when one fails -
Using subtests to distinguish "fatal asserts" from "non fatal" ones.
Alternatives: One could achieve the same result by not using a subtest for those fatal steps, instead doing those asserts in the enclosing test scope. The downside of that is purely readability. In the example above, it may be desirable to simply have the body of "sub1" indented into its own block.