vendredi 31 mai 2019

Repeat test in pytest but regard all repetitions together as one test only

I want to repeat a test and it should fail if one of those repetitions fails. So basically:

def test_example():
    for _ in range(5):
        assert random.randint(0, 1)

Is there a better way to do this? Since I'd have to modify the test function test_example itself for this (insert the for loop), I'd rather just have a decorator to do the same.

However, if I use

@pytest.mark.parametrize("reps", range(5))
def test_example(reps):
    assert random.randint(0, 1)

or

@pytest.mark.repeat(5)
def test_example():
    assert random.randint(0, 1)

I get a total of 5 tests - but I want 1 test result for all 5 tests together.

Aucun commentaire:

Enregistrer un commentaire