Skip to content

Feature idea: rerun test if condition is not met (similar to hypothesis.assume()) #3475

Closed
@rouge8

Description

@rouge8

Sometimes when running tests with semi-random data (e.g. from factory_boy), you know the test will fail if the generated data matches some condition. Rather than execute the test when you know it will fail, it would be nice if you could tell pytest to re-run that test, probably configurable up to N times. For example:

def test_something_with_different_people():
    person1, person2 = PersonFactory.build_batch(2)
    # if this is False, rerun the test up to N times
    pytest.assume(person1.name != person2.name)
    # some test that depends on the condition being true

This is inspired by assume() from hypothesis.

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