Nacht
Nacht

Reputation: 11366

Stop pytest after X consecutive fails

Currently pytest has the --maxfail=X flag that stops the whole system after X total fails.

Could someone tell me how I could do the same but instead of total fails, it be X consecutive fails?

Thanks!

Upvotes: 0

Views: 288

Answers (2)

Bel Bicalho
Bel Bicalho

Reputation: 21

Try using the --maxfail parameter. check in pytest -h:

pytest --maxfail=num

Upvotes: 1

GeorgeWilson
GeorgeWilson

Reputation: 592

I'm sure there is a better solution, but you could write a script that went through all the test you wanted one by one calling:

pass=py.test.main(test)

and keeping a counter which resets whenever pass=0 (i.e the tests pass) and throws an exception when the counter reaches X:

count=0
for tests:
    pass=py.test.main(test)
    if pass=1: count+=1
    else: count=0
    if count==X BREAK;

Upvotes: 0

Related Questions