← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #194222]: How to get line number from which a function was called in Sikuli?

 

Question #194222 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/194222

    Status: Answered => Solved

Luis Gonzalez confirmed that the question is solved:
Thank you for your answers! There are two reasons why I wouldn't like to
just omit the ELSE clause and let the exception be handled by default.

First, I would like a fancier output that matches the one of a log file
I create with all the steps of the execution (I do not run this from the
IDE, but from console since this is used for automation purposes).

Second, I want to close the application after an exception is found,
since what I do is create a list of scripts and each one of them is a
Test Case. So, if the TC fails, I want the application (Internet
Explorer) to be closed so that the next TC will have a clean slate to
start.

Than being said, I found what I needed using traceback.extract_stack. 
def xclick(img):
   if exists(img):
      click(getLastMatch())
   else:
      stack = traceback.extract_stack(limit = 2)
      print '[Error] Image not found: ' + img + ' on line' + str(stack[0][1])
      exit(1)

extract_stack returns a list of tuples, and element number 1 of that
tuple corresponds to the line number. When the function is called,
position 0 of the list of tuples will contain the return information,
including the return line number.

Thanks to both, again, for you help!

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.