I am using robotframework to run bunch of python functions as test cases. I tagged bunch of test cases as setup and bunch of test cases as cleanup. I use -i option in robot to run various tests cases. Typically I run -i setup for setting up and -i cleanup to clean up the test suite. However, if a test case in setup fails , all the test cases are still executed. I am looking for an ability to mark bunch of test cases as suite setup and suite teardown, and run suite teardown if suite setup fails automatically without running any test cases in between. I tried the Suite Setup with keywords option, but with that I am moving my test cases to keywords section and I am loosing the tags functionality.
Original robot file
*** Settings ***
Suite Setup
Suite Teardown
*** Test Cases ***
setup_1
[Tags] setup smoke 1
${result} ${result_str} = test.test.TestSetup.test_setup_1
Should Be Equal ${result} ${TRUE}
setup_2
[Tags] setup smoke 1
${result} ${result_str} = test.test.TestSetup.test_setup_2
Should Be Equal ${result} ${TRUE}
setup_3
[Tags] setup smoke 1
${result} ${result_str} = test.test.TestSetup.test_setup_3
Should Be Equal ${result} ${TRUE}
TestCase 1
[Tags] tc
${result} ${result_str} = test.test.my_func.test_func_1
Should Be Equal ${result} ${TRUE}
TestCase 2
[Tags] tc
${result} ${result_str} = test.test.my_func.test_func_2
Should Be Equal ${result} ${TRUE}
cleanup_1
[Tags] cleanup smoke 1
${result} ${result_str} = test.test.TestCleanup.test_cleanup_1
Should Be Equal ${result} ${TRUE}
cleanup_2
[Tags] cleanup smoke 1
${result} ${result_str} = test.test.TestCleanup.test_cleanup_2
Should Be Equal ${result} ${TRUE}
Robot file with keywords
*** Settings ***
Suite Setup Run keywords
... setup_1
... AND setup_2
... AND setup_3
Suite Teardown Run keywords
... cleanup_1
... AND cleanup_2
*** Keywords ***
setup_1
[Tags] setup smoke 1
${result} ${result_str} = test.test.TestSetup.test_setup_1
Should Be Equal ${result} ${TRUE}
setup_2
[Tags] setup smoke 1
${result} ${result_str} = test.test.TestSetup.test_setup_2
Should Be Equal ${result} ${TRUE}
setup_3
[Tags] setup smoke 1
${result} ${result_str} = test.test.TestSetup.test_setup_3
Should Be Equal ${result} ${TRUE}
cleanup_1
[Tags] cleanup smoke 1
${result} ${result_str} = test.test.TestCleanup.test_cleanup_1
Should Be Equal ${result} ${TRUE}
cleanup_2
[Tags] cleanup smoke 1
${result} ${result_str} = test.test.TestCleanup.test_cleanup_2
Should Be Equal ${result} ${TRUE}
*** Test Cases ***
TestCase 1
[Tags] tc
${result} ${result_str} = test.test.my_func.test_func_1
Should Be Equal ${result} ${TRUE}
TestCase 2
[Tags] tc
${result} ${result_str} = test.test.my_func.test_func_2
Should Be Equal ${result} ${TRUE}
Is there any way to mark tests that are tagged with setup as Suite Setup and mark tests that are tagged with cleanup as Suite Teardown and still have an ability to run individual tests in setup and teardown?
Keywords
section. Why are including the setup and tear-down in the test cases section? What exactly are you trying to achieve by doing this? Are the keywords in the setup and tear-down also test cases that you want to execute? – Sameem