From what I can tell the docs recommend issuing a 'Ctrl-C' to abort an execution of a '.robot' file (test case/suite). I was wondering if there was a way to add a cleanup mechanism whenever this 'Ctrl-C' is issued? If not, can you suggest which robot api libraries I can use to enhance?
Asked
Active
Viewed 1,038 times
1
-
Can you elaborate more on the use case for this functionality? Why would the a Ctrl C be needed for in your case that much? – A. Kootstra Nov 26 '17 at 11:45
-
If user wants to stop test in middle of robot test case/suite execution, I want my robot script to do a clean up. This is very useful when dealing with changing configuration for a test and reverting it back at end of execution. – ozn Nov 27 '17 at 04:08
-
I think the answer from @bryan is the right one. However, I'm still on the fence as to why breaking off should be considered common practice instead of an exceptional act. In my mind using the arguments to pick a specific test case would be preferred to breaking off a run of several after the desired one has finished. – A. Kootstra Nov 27 '17 at 06:05
-
Ideally, it should be required. Its just a possible scenario that I am trying to handle. I have requirement to be able to do this. That's the main reason. To be more specific, my usecase involves running tests where I change the network configuration, and for whatever reasons user wants to gracefully stop a test, it should revert back the network changes. – ozn Nov 28 '17 at 18:42
1 Answers
2
If you stop execution using control-c from the console, robot will still run your teardown commands.
From the user guide:
The execution is stopped when Ctrl-C is pressed in the console where the tests are running. ... By default teardowns of the tests and suites that have been started are executed even if the test execution is stopped using one of the methods above. This allows clean-up activities to be run regardless how execution ends.

Bryan Oakley
- 370,779
- 53
- 539
- 685
-
I'm not sure about that. Looking at the user guide [link](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pressing-ctrl-c) This is what it says: > The execution is stopped when Ctrl-C is pressed in the console where the tests are running. When running the tests on Python, the execution is stopped immediately, but with Jython it ends only after the currently executing keyword ends. If Ctrl-C is pressed again, the execution ends immediately and reports and logs are not created. – ozn Nov 27 '17 at 04:25
-
I guess I'l recant my comment above. Thanks for the information. This link provides more information on what you were talking about: https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/ExecutingTestCases/TestExecution.rst#setups-and-teardowns I was looking for 'teardown'. I'm still looking for a good example on how that works but I think it likely suffices my need for now. – ozn Nov 28 '17 at 18:55