Skip to content

Feature Request: Programmatically stop execution upon first failed subtest #187

Closed as not planned
@rhoban13

Description

@rhoban13

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:

  1. 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

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions