@@ -537,7 +537,7 @@ def suspend_capturing(self, in_: bool = False) -> None:
537
537
self ._in_suspended = True
538
538
539
539
def resume_capturing (self ) -> None :
540
- self ._state = "resumed "
540
+ self ._state = "started "
541
541
if self .out :
542
542
self .out .resume ()
543
543
if self .err :
@@ -558,6 +558,10 @@ def stop_capturing(self) -> None:
558
558
if self .in_ :
559
559
self .in_ .done ()
560
560
561
+ def is_started (self ) -> bool :
562
+ """Whether actively capturing -- not suspended or stopped."""
563
+ return self ._state == "started"
564
+
561
565
def readouterr (self ) -> CaptureResult :
562
566
if self .out :
563
567
out = self .out .snap ()
@@ -697,11 +701,19 @@ def resume_fixture(self) -> None:
697
701
@contextlib .contextmanager
698
702
def global_and_fixture_disabled (self ) -> Generator [None , None , None ]:
699
703
"""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 ()
701
710
try :
702
711
yield
703
712
finally :
704
- self .resume ()
713
+ if do_global :
714
+ self .resume_global_capture ()
715
+ if do_fixture :
716
+ self .resume_fixture ()
705
717
706
718
@contextlib .contextmanager
707
719
def item_capture (self , when : str , item : Item ) -> Generator [None , None , None ]:
@@ -810,6 +822,12 @@ def _resume(self) -> None:
810
822
if self ._capture is not None :
811
823
self ._capture .resume_capturing ()
812
824
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
+
813
831
@contextlib .contextmanager
814
832
def disabled (self ) -> Generator [None , None , None ]:
815
833
"""Temporarily disables capture while inside the 'with' block."""
0 commit comments