@@ -167,8 +167,12 @@ def test_lifecycle(self):
167167 window = ApplicationWindow ()
168168 app .observe (lambda _ : app .add_window (window ), "started" )
169169
170+ def on_started (event ):
171+ self .gui .invoke_after (100 , app .exit )
172+
173+ app .observe (on_started , "started" )
174+
170175 with self .assertMultiTraitChanges ([app ], EVENTS , []):
171- self .gui .invoke_after (1000 , app .exit )
172176 result = app .run ()
173177
174178 self .assertTrue (result )
@@ -180,9 +184,14 @@ def test_exit_prepare_error(self):
180184 app = TestingApp (exit_prepared_error = True )
181185 self .connect_listeners (app )
182186
183- with self .assertMultiTraitChanges ([app ], EVENTS , []):
184- self .gui .invoke_after (1000 , app .exit )
185- result = app .run ()
187+ def on_started (event ):
188+ self .gui .invoke_after (100 , app .exit )
189+
190+ app .observe (on_started , "started" )
191+
192+ with self .assertLogs ("pyface.application" , "WARNING" ) as logs_cm :
193+ with self .assertMultiTraitChanges ([app ], EVENTS , []):
194+ result = app .run ()
186195
187196 self .assertTrue (result )
188197 self .assertFalse (app .exit_vetoed )
@@ -191,6 +200,10 @@ def test_exit_prepare_error(self):
191200 self .assertEqual (event_order , EVENTS )
192201 self .assertEqual (app .windows , [])
193202
203+ self .assertEqual (len (logs_cm .output ), 1 )
204+ [log_output ] = logs_cm .output
205+ self .assertIn ("Error preparing for application exit" , log_output )
206+
194207 def test_veto_exit (self ):
195208 app = TestingApp (veto_exit = True )
196209 self .connect_listeners (app )
@@ -211,8 +224,12 @@ def test_veto_open_window(self):
211224 app = TestingApp (veto_open_window = True )
212225 self .connect_listeners (app )
213226
214- with self . assertMultiTraitChanges ([ app ], EVENTS , [] ):
227+ def on_started ( event ):
215228 self .gui .invoke_after (1000 , app .exit )
229+
230+ app .observe (on_started , "started" )
231+
232+ with self .assertMultiTraitChanges ([app ], EVENTS , []):
216233 result = app .run ()
217234
218235 self .assertTrue (result )
@@ -227,9 +244,13 @@ def test_veto_close_window(self):
227244 app = TestingApp (veto_close_window = True )
228245 self .connect_listeners (app )
229246
230- with self . assertMultiTraitChanges ([ app ], EVENTS , [] ):
247+ def on_started ( event ):
231248 self .gui .invoke_after (1000 , app .exit )
232249 self .gui .invoke_after (2000 , app .exit , force = True )
250+
251+ app .observe (on_started , "started" )
252+
253+ with self .assertMultiTraitChanges ([app ], EVENTS , []):
233254 result = app .run ()
234255
235256 self .assertTrue (result )
@@ -243,8 +264,12 @@ def test_force_exit(self):
243264 app = TestingApp (do_exit = True , force_exit = True , veto_exit = True )
244265 self .connect_listeners (app )
245266
246- with self . assertMultiTraitChanges ([ app ], EVENTS , [] ):
267+ def on_started ( event ):
247268 self .gui .invoke_after (100 , app .exit , True )
269+
270+ app .observe (on_started , "started" )
271+
272+ with self .assertMultiTraitChanges ([app ], EVENTS , []):
248273 result = app .run ()
249274
250275 self .assertTrue (result )
@@ -258,8 +283,12 @@ def test_force_exit_close_veto(self):
258283 app = TestingApp (do_exit = True , force_exit = True , veto_close_window = True )
259284 self .connect_listeners (app )
260285
286+ def on_started (event ):
287+ self .gui .invoke_after (100 , app .exit , True )
288+
289+ app .observe (on_started , "started" )
290+
261291 with self .assertMultiTraitChanges ([app ], EVENTS , []):
262- self .gui .invoke_after (1000 , app .exit , True )
263292 result = app .run ()
264293
265294 self .assertTrue (result )
@@ -285,8 +314,12 @@ def test_bad_stop(self):
285314 app = TestingApp (stop_cleanly = False )
286315 self .connect_listeners (app )
287316
317+ def on_started (event ):
318+ self .gui .invoke_after (100 , app .exit )
319+
320+ app .observe (on_started , "started" )
321+
288322 with self .assertMultiTraitChanges ([app ], EVENTS [:- 1 ], EVENTS [- 1 :]):
289- self .gui .invoke_after (1000 , app .exit , True )
290323 result = app .run ()
291324
292325 self .assertFalse (result )
0 commit comments