@@ -537,7 +537,7 @@ def suspend_capturing(self, in_: bool = False) -> None:
537537 self ._in_suspended = True
538538
539539 def resume_capturing (self ) -> None :
540- self ._state = "resumed "
540+ self ._state = "started "
541541 if self .out :
542542 self .out .resume ()
543543 if self .err :
@@ -558,6 +558,10 @@ def stop_capturing(self) -> None:
558558 if self .in_ :
559559 self .in_ .done ()
560560
561+ def is_started (self ) -> bool :
562+ """Whether actively capturing -- not suspended or stopped."""
563+ return self ._state == "started"
564+
561565 def readouterr (self ) -> CaptureResult :
562566 if self .out :
563567 out = self .out .snap ()
@@ -697,11 +701,19 @@ def resume_fixture(self) -> None:
697701 @contextlib .contextmanager
698702 def global_and_fixture_disabled (self ) -> Generator [None , None , None ]:
699703 """Context manager to temporarily disable global and current fixture capturing."""
700- self .suspend ()
704+ do_fixture = self ._capture_fixture and self ._capture_fixture ._is_started ()
705+ if do_fixture :
706+ self .suspend_fixture ()
707+ do_global = self ._global_capturing and self ._global_capturing .is_started ()
708+ if do_global :
709+ self .suspend_global_capture ()
701710 try :
702711 yield
703712 finally :
704- self .resume ()
713+ if do_global :
714+ self .resume_global_capture ()
715+ if do_fixture :
716+ self .resume_fixture ()
705717
706718 @contextlib .contextmanager
707719 def item_capture (self , when : str , item : Item ) -> Generator [None , None , None ]:
@@ -810,6 +822,12 @@ def _resume(self) -> None:
810822 if self ._capture is not None :
811823 self ._capture .resume_capturing ()
812824
825+ def _is_started (self ) -> bool :
826+ """Whether actively capturing -- not disabled or closed."""
827+ if self ._capture is not None :
828+ return self ._capture .is_started ()
829+ return False
830+
813831 @contextlib .contextmanager
814832 def disabled (self ) -> Generator [None , None , None ]:
815833 """Temporarily disables capture while inside the 'with' block."""
0 commit comments