@@ -94,19 +94,27 @@ class Test(object):
9494 # them as fields so they can be accessed from the main thread.
9595 def run (self ):
9696 """Executes this testapp."""
97- result = subprocess .run (
98- args = [self .testapp_path ],
99- cwd = os .path .dirname (self .testapp_path ), # Testapp checks CWD for config
100- stdout = subprocess .PIPE ,
101- stderr = subprocess .STDOUT ,
102- text = True ,
103- check = False ,
104- timeout = 300 )
97+ result = None # Ensures this var is defined if timeout occurs.
98+ try :
99+ result = subprocess .run (
100+ args = [self .testapp_path ],
101+ cwd = os .path .dirname (self .testapp_path ), # Testapp uses CWD for config
102+ stdout = subprocess .PIPE ,
103+ stderr = subprocess .STDOUT ,
104+ text = True ,
105+ check = False ,
106+ timeout = 300 )
107+ except subprocess .TimeoutExpired as e :
108+ logging .error ("Testapp timed out!" )
109+ # e.output will sometimes be bytes, sometimes string. Decode if needed.
110+ try :
111+ self .logs = e .output .decode ()
112+ except AttributeError : # This will happen if it's already a string.
113+ self .logs = e .output
114+ if result :
115+ self .logs = result .stdout
105116 logging .info ("Finished running %s" , self .testapp_path )
106117
107- self .logs = result .stdout
108- self .return_code = result .returncode
109-
110118
111119if __name__ == "__main__" :
112120 app .run (main )
0 commit comments