# Rerun failed robot tc in teardown

**URL:** <https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340>\
**Category:** Robot Framework\
**Created:** [29 January 2025 08:31 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340 "2025-01-29T08:31:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSML](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ssml/32/4485_2.png) [@SSML](https://forum.robotframework.org/u/SSML)\
**Post date:** [29 January 2025 08:31 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/1 "2025-01-29T08:31:48Z")

</div>

I have a robot test case, in teardown I need to check if the test case failed, I need to rerun the entire test case… how to do it in robot framework

---

<div class="post-metadata">

**Author:** ![hyytiainen](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@hyytiainen](https://forum.robotframework.org/u/hyytiainen)\
**Post date:** [29 January 2025 08:51 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/2 "2025-01-29T08:51:16Z")

</div>

Hi,  
Check this:  
[https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html?\_ga=2.37241376.1827002870.1738130098-151480807.1700649855#toc-entry-514](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html?_ga=2.37241376.1827002870.1738130098-151480807.1700649855#toc-entry-514)

Br,  
Sami

---

<div class="post-metadata">

**Author:** ![FrancisG](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/francisg/32/4247_2.png) [@FrancisG](https://forum.robotframework.org/u/FrancisG)\
**Post date:** [29 January 2025 09:08 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/3 "2025-01-29T09:08:08Z")

</div>

What teardown are you talking about? Test teardown or suite teardown?

There is [a built-in feature to rerun failed tests only](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#re-executing-failed-test-cases), but this is based on rerunning the whole robot command, with the `--rerunfailed output.xml` where output.xml is the result of the previous run.

If this is not what you are looking for (since you are mentioning teardown) a solution could be to put all your test logic into a keyword, monitor if the keyword fails and rerun it accordingly.  
However, I would suggest doing that in the body of the test rather than in the teardown, since teardown have a default behaviour of “recursive-continuing-on-failure” which is probably not appropriate to your test case.

See [here](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-setup-and-teardown):

> The test teardown is special in two ways. First of all, it is executed also when a test case fails, so it can be used for clean-up activities that must be done regardless of the test case status. In addition, all the keywords in the teardown are also executed even if one of them fails. This [continue on failure](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#continue-on-failure) functionality can be used also with normal keywords, but inside teardowns it is on by default.

On the topic of how to rerun a keyword (eg. if you put all your test case into a single keyword, for rerunning purpose), there are multiple ways to proceed:

- using keywords like [Wait Until Keyword Succeeds](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Wait%20Until%20Keyword%20Succeeds) or [Run Keyword And Return Status](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Return%20Status)
- using the [TRY/EXCEPT syntax](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#try-except-syntax)
- using a [WHILE loop](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#while-loops) which condition would be to loop until the keyword status is successful and use the settings `limit` (eg. 2 or 2min), `on_limit` (eg. fail) and `on_limit_message` (eg. TC failed on retries too.) to define the number of retries and the error message.

What option is available to you depends on which version of RobotFramework you are using.

---

<div class="post-metadata">

**Author:** ![norma44shah](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@norma44shah](https://forum.robotframework.org/u/norma44shah)\
**Post date:** [29 January 2025 09:44 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/4 "2025-01-29T09:44:13Z")

</div>

To rerun a test case in Robot Framework if it fails, you can use the **RetryFailed Listener**. This listener automatically retries tests or tasks based on tags. Here’s how you can set it up:

1. **Install the Listener** : Install the `robotframework-retryfailed` package using pip:

2. **Add the Listener** : Add the listener to your Robot Framework execution. You can specify the number of retries for each test case using tags.

3. **Tagging Tests** : Tag your test cases with `test:retry(n)` where `n` is the number of retries you want.

4. **Run the Tests** : Execute your tests with the listener. The listener will automatically retry the tests based on the tags.

---

<div class="post-metadata">

**Author:** ![FrancisG](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/francisg/32/4247_2.png) [@FrancisG](https://forum.robotframework.org/u/FrancisG)\
**Post date:** [29 January 2025 11:10 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/5 "2025-01-29T11:10:26Z")

</div>

It also seems possible to do using listener.

> **[Re-Execute failed tests | ROBOT FRAMEWORK](https://docs.robotframework.org/docs/flaky_tests)**
>
> HOW TO! Rerun failed testcases in Robot Framework

---

<div class="post-metadata">

**Author:** ![SSML](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ssml/32/4485_2.png) [@SSML](https://forum.robotframework.org/u/SSML)\
**Post date:** [29 January 2025 13:25 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/6 "2025-01-29T13:25:05Z")

</div>

I am running GUI Testcases, If one the testcase fails, i have created Test Teardown, where i check the test execution status, if the test case failed, i need to re-run the test case, so that next it passes. I am not looking for re-run failed testcase at the end of exeuction

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [29 January 2025 14:51 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/7 "2025-01-29T14:51:45Z")

</div>

there’s also this; [GitHub - MarketSquare/robotframework-retryfailed: A listener to automatically retry tests or tasks based on tags.](https://github.com/MarketSquare/robotframework-retryfailed)

but i’d guess its based on same principle as to what @FrancisG suggested.

---

<div class="post-metadata">

**Author:** ![SSML](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ssml/32/4485_2.png) [@SSML](https://forum.robotframework.org/u/SSML)\
**Post date:** [31 January 2025 01:38 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/8 "2025-01-31T01:38:16Z")

</div>

Thank you Francis, will try.

---

<div class="post-metadata">

**Author:** ![SSML](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ssml/32/4485_2.png) [@SSML](https://forum.robotframework.org/u/SSML)\
**Post date:** [31 January 2025 01:40 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/9 "2025-01-31T01:40:28Z")

</div>

Thanks francis

---

<div class="post-metadata">

**Author:** ![SSML](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ssml/32/4485_2.png) [@SSML](https://forum.robotframework.org/u/SSML)\
**Post date:** [31 January 2025 01:42 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/10 "2025-01-31T01:42:58Z")

</div>

Thanks rasjani… will try that

---

<div class="post-metadata">

**Author:** ![SSML](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ssml/32/4485_2.png) [@SSML](https://forum.robotframework.org/u/SSML)\
**Post date:** [31 January 2025 01:43 UTC](https://forum.robotframework.org/t/rerun-failed-robot-tc-in-teardown/8340/11 "2025-01-31T01:43:28Z")

</div>

Thanks sami will try this
