Is there a possibility in Robot Framework to allow executing a custom keyword only in Test Setup part (or alternatively in Test Teardown)? Assuming that I have a keyword called My Setup
. If My Setup
is executed in a normal step (i.e. not in Test Setup), the test should fail. RF Documentation about User keywords and browsing through StackOverflow didn't give me any meaningful results.
For example, the documentation in Robot Framework's built-in function Run keyword if all tests passed
states that "Trying to use it anywhere else results in an error", so I was wondering that there should be some kind of way to apply this for custom keywords, too.
I have tried to fix this by parsing the test file before starting the test execution and checking for any occurences of My Setup
that are not in Test Setup. This, however, feels very cumbersome, so what I'm looking for is something like following:
def MySetup(self, some_arg):
if MAGIC.not_inside_test_setup():
raise AssertionError('"My Setup" can be executed only in Test Setup')