@@ -117,6 +117,7 @@ class RequestedState(Enum):
117117 Next = 2
118118 StepIn = 3
119119 StepOut = 4
120+ Running = 5
120121
121122
122123class BreakpointsEntry (NamedTuple ):
@@ -338,25 +339,16 @@ def stop(self) -> None:
338339
339340 self .condition .notify_all ()
340341
341- def continue_all (self , send_event : bool = True ) -> None :
342+ def continue_all (self ) -> None :
342343 if self .main_thread is not None and self .main_thread .ident is not None :
343- self .continue_thread (self .main_thread .ident , send_event )
344+ self .continue_thread (self .main_thread .ident )
344345
345- def continue_thread (self , thread_id : int , send_event : bool = False ) -> None :
346+ def continue_thread (self , thread_id : int ) -> None :
346347 if self .main_thread is None or thread_id != self .main_thread .ident :
347348 raise InvalidThreadIdError (thread_id )
348349
349350 with self .condition :
350- if send_event :
351- self .send_event (
352- self ,
353- ContinuedEvent (
354- body = ContinuedEventBody (thread_id = self .main_thread .ident , all_threads_continued = True )
355- ),
356- )
357-
358- self .requested_state = RequestedState .Nothing
359- self .state = State .Running
351+ self .requested_state = RequestedState .Running
360352 self .condition .notify_all ()
361353
362354 def pause_thread (self , thread_id : int ) -> None :
@@ -365,7 +357,6 @@ def pause_thread(self, thread_id: int) -> None:
365357
366358 with self .condition :
367359 self .requested_state = RequestedState .Pause
368- self .state = State .Paused
369360
370361 self .condition .notify_all ()
371362
@@ -374,8 +365,6 @@ def next(self, thread_id: int, granularity: Optional[SteppingGranularity] = None
374365 raise InvalidThreadIdError (thread_id )
375366
376367 with self .condition :
377- self .state = State .Running
378-
379368 if self .full_stack_frames and self .full_stack_frames [0 ].type in ["TEST" , "SUITE" ]:
380369 self .requested_state = RequestedState .StepIn
381370 else :
@@ -406,7 +395,6 @@ def step_in(
406395
407396 with self .condition :
408397 self .requested_state = RequestedState .StepIn
409- self .state = State .Running
410398
411399 self .condition .notify_all ()
412400
@@ -416,7 +404,6 @@ def step_out(self, thread_id: int, granularity: Optional[SteppingGranularity] =
416404
417405 with self .condition :
418406 self .requested_state = RequestedState .StepOut
419- self .state = State .Running
420407 self .stop_stack_len = len (self .full_stack_frames ) - 1
421408
422409 i = 1
@@ -474,7 +461,9 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
474461 return
475462
476463 if self .requested_state == RequestedState .Pause :
464+ self .requested_state = RequestedState .Nothing
477465 self .state = State .Paused
466+
478467 self .send_event (
479468 self ,
480469 StoppedEvent (
@@ -484,10 +473,12 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
484473 )
485474 ),
486475 )
487- self . requested_state = RequestedState . Nothing
476+
488477 elif self .requested_state == RequestedState .Next :
489478 if len (self .full_stack_frames ) <= self .stop_stack_len :
490479 self .state = State .Paused
480+ self .requested_state = RequestedState .Nothing
481+
491482 self .send_event (
492483 self ,
493484 StoppedEvent (
@@ -497,9 +488,11 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
497488 )
498489 ),
499490 )
500- self . requested_state = RequestedState . Nothing
491+
501492 elif self .requested_state == RequestedState .StepIn :
502493 self .state = State .Paused
494+ self .requested_state = RequestedState .Nothing
495+
503496 self .send_event (
504497 self ,
505498 StoppedEvent (
@@ -509,9 +502,11 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
509502 )
510503 ),
511504 )
512- self . requested_state = RequestedState . Nothing
505+
513506 elif self .requested_state == RequestedState .StepOut and len (self .full_stack_frames ) <= self .stop_stack_len :
514507 self .state = State .Paused
508+ self .requested_state = RequestedState .Nothing
509+
515510 self .send_event (
516511 self ,
517512 StoppedEvent (
@@ -521,7 +516,6 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
521516 )
522517 ),
523518 )
524- self .requested_state = RequestedState .Nothing
525519
526520 if source is not None :
527521 source_path = self .map_path_to_client (str (Path (source ).absolute ()))
@@ -576,8 +570,9 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
576570 )
577571 return
578572
579- self .requested_state = RequestedState .Nothing
580573 self .state = State .Paused
574+ self .requested_state = RequestedState .Nothing
575+
581576 self .send_event (
582577 self ,
583578 StoppedEvent (
@@ -590,6 +585,52 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
590585 )
591586
592587 def process_end_state (self , status : str , filter_id : Set [str ], description : str , text : Optional [str ]) -> None :
588+ if self .state == State .Stopped :
589+ return
590+
591+ if self .requested_state == RequestedState .Next :
592+ if len (self .full_stack_frames ) <= self .stop_stack_len :
593+ self .state = State .Paused
594+ self .requested_state = RequestedState .Nothing
595+
596+ self .send_event (
597+ self ,
598+ StoppedEvent (
599+ body = StoppedEventBody (
600+ reason = StoppedReason .STEP ,
601+ thread_id = threading .current_thread ().ident ,
602+ )
603+ ),
604+ )
605+
606+ elif self .requested_state == RequestedState .StepIn :
607+ self .state = State .Paused
608+ self .requested_state = RequestedState .Nothing
609+
610+ self .send_event (
611+ self ,
612+ StoppedEvent (
613+ body = StoppedEventBody (
614+ reason = StoppedReason .STEP ,
615+ thread_id = threading .current_thread ().ident ,
616+ )
617+ ),
618+ )
619+
620+ elif self .requested_state == RequestedState .StepOut and len (self .full_stack_frames ) <= self .stop_stack_len :
621+ self .state = State .Paused
622+ self .requested_state = RequestedState .Nothing
623+
624+ self .send_event (
625+ self ,
626+ StoppedEvent (
627+ body = StoppedEventBody (
628+ reason = StoppedReason .STEP ,
629+ thread_id = threading .current_thread ().ident ,
630+ )
631+ ),
632+ )
633+
593634 if (
594635 not self .terminated
595636 and status == "FAIL"
@@ -599,17 +640,18 @@ def process_end_state(self, status: str, filter_id: Set[str], description: str,
599640 if v .filter_options and any (o for o in v .filter_options if o .filter_id in filter_id )
600641 )
601642 ):
602- self .requested_state = RequestedState .Nothing
643+ reason = StoppedReason .EXCEPTION
644+
603645 self .state = State .Paused
646+ self .requested_state = RequestedState .Nothing
604647
605648 self .send_event (
606649 self ,
607650 StoppedEvent (
608651 body = StoppedEventBody (
609- description = description ,
610- reason = StoppedReason .EXCEPTION ,
652+ reason = reason ,
611653 thread_id = threading .current_thread ().ident ,
612- all_threads_stopped = True ,
654+ description = description ,
613655 text = text ,
614656 )
615657 ),
@@ -619,7 +661,10 @@ def wait_for_running(self) -> None:
619661 if self .attached :
620662 while True :
621663 with self .condition :
622- self .condition .wait_for (lambda : self .state in [State .Running , State .Stopped , State .CallKeyword ])
664+ self .condition .wait_for (
665+ lambda : self .state in [State .Running , State .Stopped , State .CallKeyword ]
666+ or self .requested_state != RequestedState .Nothing
667+ )
623668
624669 if self .state == State .CallKeyword :
625670 self ._evaluated_keyword_result = None
@@ -637,6 +682,18 @@ def wait_for_running(self) -> None:
637682
638683 continue
639684
685+ if self .requested_state == RequestedState .Running :
686+ self .state = State .Running
687+ if self .main_thread is not None and self .main_thread .ident is not None :
688+ self .send_event (
689+ self ,
690+ ContinuedEvent (
691+ body = ContinuedEventBody (thread_id = self .main_thread .ident , all_threads_continued = True )
692+ ),
693+ )
694+ self .requested_state = RequestedState .Nothing
695+ continue
696+
640697 break
641698
642699 def start_output_group (self , name : str , attributes : Dict [str , Any ], type : Optional [str ] = None ) -> None :
@@ -769,6 +826,7 @@ def start_suite(self, name: str, attributes: Dict[str, Any]) -> None:
769826 if self .stop_on_entry :
770827 self .stop_on_entry = False
771828
829+ self .requested_state = RequestedState .Nothing
772830 self .state = State .Paused
773831 self .send_event (
774832 self ,
0 commit comments