Re-run failed tests in behave BDD

Tutorial​​ 19​​ ​​ ​​ Re-run failed tests in behave​​ BDD

Welcome to the 19th article in Behave BDD series!

What you will Learn :

  • Rerun failed tests​​ ​​ 

How to Re-run failed tests in behave

Many a times your automation test might fail due to some network issues etc.​​ So you may want to re-run the failed tests​​ one more time.​​ This article is about how to automatically re-run our failed tests.

We have 5 features as seen below

Let us execute behave command. This will execute all the feature files

Notice below that 1 feature failed (you might see different results)

Execute​​ behave –format help​​ command

As you can see above, we get a list of all the formatters. One of them is ‘rerun’.​​ So rerun is one of the formatter.

We will now use ‘rerun’ formatter in the below command. This command would​​ automatically create the feature file​​ ‘failed_tests_iteration1.feature’ and will​​ send the failed tests output​​ into​​ it​​ (-o is for output)

behave -f rerun -o failed_tests_iteration1.feature --no-capture


After the test execution, you would see the failed_tests_iteration1.feature being automatically created, see below. If you don’t see it, just refresh the project folder

Let us see the contents of this feature file. It mentions the tests that failed. So it has lists of all the failed tests

Let us now execute​​ behave @failed_tests_iteration1.feature

This command will run whatever tests are mentioned in the ‘failed_tests_iteration1.feature’ file

Notice this time that only failed tests were executed.

Let us now execute the ‘behave’ command.

As​​ you can see above,​​ an​​ error is thrown. The reason being, ‘behave’ command would execute all the feature files inside that resoective folder. However the below feature file is not like other regular feature files that we create

Let us execute​​ behave –help​​ command


As you can see above, we have an exclude -e command that we can utilize. This will help us to exclude failed_tests_iteration1.feature

So let us execute​​ behave -e failed_tests_iteration1.feature

Now if you notice, the behave command is executed as expected. The output might vary on your machine (depends what feature files you might have written)







Thank you​​ for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 31st DEC 2024