@@ -822,6 +822,7 @@ def test_cancel_notify(
822822 # Test that NOTIFY_THEN_CANCEL first signals a SIGTERM and then a SIGKILL
823823
824824 # GIVEN
825+ proc_id : Optional [int ] = None
825826 logger = build_logger (queue_handler )
826827 with NotifyingRunner (logger = logger , session_working_directory = tmp_path ) as runner :
827828 python_app_loc = (
@@ -833,6 +834,11 @@ def test_cancel_notify(
833834 secs = 2 if not is_windows () else 5
834835 time .sleep (secs ) # Give the process a little time to do something
835836 now = datetime .now (timezone .utc )
837+
838+ assert runner ._process is not None
839+ assert runner ._process ._pid is not None
840+ proc_id = runner ._process ._pid
841+
836842 runner .cancel (time_limit = timedelta (seconds = 2 ))
837843
838844 # THEN
@@ -849,9 +855,12 @@ def test_cancel_notify(
849855 messages = collect_queue_messages (message_queue )
850856 assert "Trapped" in messages
851857 trapped_idx = messages .index ("Trapped" )
858+ process_exit_idx = messages .index (
859+ f"Process pid { proc_id } exited with code: { runner .exit_code } (unsigned) / { hex (runner .exit_code )} (hex)"
860+ )
852861 # Should be at least one more number printed after the Trapped
853862 # to indicate that we didn't immediately terminate the script.
854- assert messages [trapped_idx + 1 ]. isdigit ( )
863+ assert any ( msg . isdigit () for msg in messages [trapped_idx + 1 : process_exit_idx ] )
855864 # Didn't get to the end
856865 assert "Log from test 9" not in messages
857866 # Notification file exists
0 commit comments