pytest-dev / pytest-dev/pytest-rerunfailures

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

Open
#58 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
477
Forks
107
Avg merge
2d 14h
Merged PRs (30d)
21

Description

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 True, rerun the test up to N times
    rerun_if(person1.name == person2.name)
    # some test that depends on `person1.name != person2.name`

This is inspired by assume() from hypothesis.

Originally opened as https://github.com/pytest-dev/pytest/issues/3475

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the requested rerun_if behavior, its similarity to Hypothesis assume(), and pytest's existing rerun configuration. No files, tests, or entry points are named; done would require an agreed design for detecting the condition, limiting retries to N, and verifying the behavior with tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.