stopping test case execution via listener

680 views
Skip to first unread message

Sunil

unread,
Jan 8, 2014, 10:05:13 PM1/8/14
to robotframe...@googlegroups.com
I am currently using listener to log the test results into database so as to see the execution status on runtime. I want to stop the execution if one of my critical tests fail, can this be done? API documentation does not talk about it though.

Kevin O.

unread,
Jan 8, 2014, 10:22:36 PM1/8/14
to robotframe...@googlegroups.com
Is there a reason this must be done from a listener?
Running tests already has this option:
--exitonfailure
  Stops execution immediately if a critical test fails.


Sunil

unread,
Jan 10, 2014, 5:13:10 AM1/10/14
to robotframe...@googlegroups.com
This is basically to stop test case execution if a specific keyword fails, though this is not the best approach, i am trying to figure out a way to do this through listener. The reason being I have plenty of test cases and do not want to go and update all of the individual tests.

Pekka Klärck

unread,
Jan 10, 2014, 6:29:22 AM1/10/14
to sdars...@gmail.com, robotframework-users
2014/1/9 Sunil <sdars...@gmail.com>:
As Kevin pointed out, stopping execution if a critical test fails is
easiest accomplished with `--ExitOnFailure` option.

If you want to do it based on some other criteria, using a listener
like you have been planning might be a good idea but unfortunately I
don't think there are any generic and safe way to do it.

On Python and outside Windows you should be able to use
`os.kill(os.getpid(), signal.SIGINT)` to send same signal that Ctrl-C
sends to stop execution gracefully. If that's not enough, you can use
Robot's internal signal handler directly:

from robot.running.signalhandler import STOP_SIGNAL_MONITOR
import signal

def end_keyword(<args>):
if <condition>:
STOP_SIGNAL_MONITOR(signal.SIGINT, None)


The above solution (after filling the blanks and making sure you only
send the signal once) ought to work regardless the operating system
and Python interpreter. The problem with it is that
STOP_SIGNAL_MONITOR is not part of the public API and thus subject to
change at least in major versions. How you need to use it in this
particulate case is also pretty ugly.

Having a cleaner way to stop execution via the listener interface and
also by libraries (they can already now use fatal exceptions, though)
would be nice. Please submit an enhancement request to Robot's tracker
if you think it would be useful. There are some changes needed to
signal handling anyway in 2.8.4 [1] so perhaps we could do a bit
larger rewrite then.

[1] http://code.google.com/p/robotframework/issues/detail?id=1617

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages