Luxoft / Twister

Twister Test Automation Framework
http://www.twistertesting.com/
Apache License 2.0
38 stars 21 forks source link

Syntax error inside threading function, not displayed by twister.. #179

Closed Hamza989 closed 8 years ago

Hamza989 commented 8 years ago

If there is any syntax error inside threading function, It is not handled by twister.

It just come out of the function without giving any error. This is not python behavior. Please try to solve this issue

Issue found twister build v 3.057

please run the following python code using twister and see there is no error printed on the screen.

import threading class test: def init(self): syntaxError

def funThreadPillar(): tt=test()

thrd1 = threading. Thread(target=funThreadPillar) thrd1.start()

OUTPUT FROM THE TWISTER

===== ===== ===== ===== ===== Starting suite 101 - Test_hamza ===== ===== ===== ===== =====

<<< START filename: 1001:/opt/Tests//Boundary_Tool/threadIssueHmz.py >>>

File /opt/Tests//Boundary_Tool/threadIssueHmz.py returned None. <<<

Test statistics: Start time 2015-10-20 22:18:15 -- End time 2015-10-20 22:18:15 -- 0.20 sec.

<<< END filename: 1001:/opt/Tests//Boundary_Tool/threadIssueHmz.py >>>

. . . All tests done . . .

Actual error message is displayed from python is as follows [root@BG-SUNVM1-08 Boundary_Tool]# python threadIssueHmz.py Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib64/python2.7/threading.py", line 811, in *bootstrap_inner self.run() File "/usr/lib64/python2.7/threading.py", line 764, in run self.__target(_self.__args, _self.kwargs) File "threadIssueHmz.py", line 7, in funThreadPillar tt=test() File "threadIssueHmz.py", line 4, in init** syntaxError NameError: global name 'syntaxError' is not defined

bogdanpopescu commented 8 years ago

@Hamza989

Hi, the thread is not using the same stderr as when you run the script from terminal, so this is why you cannot see the exception in teh CLI log. The solution is to use the threading library that we provide in Twister ( TscThreadLib ) to get what you need. You can check test_py_threads.py file for some examples of using TscThreadLib. Your script will become:

start script

from TscThreadsLib import tasks_reset, tasks_append, tasks_start

class test: def init(self): syntaxError

def funThreadPillar(): tt=test() return True

def test_run(): tasks_reset() tasks_append(funThreadPillar)

#tasks_start runs each task appended with tasks_append
#error_code is a list that contains the result of each task
#in case an exception is rised, the result coresponding to that
#task is False
error_code = tasks_start()[0]
return 'FAIL' if error_code == False else 'PASS'

_RESULT = test_run()

end script

Hamza989 commented 8 years ago

Thank your reply .... Yes it work fine with twister provided library