@@ -592,7 +592,7 @@ def suspend_capturing(self, in_: bool = False) -> None:
592
592
self ._in_suspended = True
593
593
594
594
def resume_capturing (self ) -> None :
595
- self ._state = "resumed "
595
+ self ._state = "started "
596
596
if self .out :
597
597
self .out .resume ()
598
598
if self .err :
@@ -613,6 +613,10 @@ def stop_capturing(self) -> None:
613
613
if self .in_ :
614
614
self .in_ .done ()
615
615
616
+ def is_started (self ) -> bool :
617
+ """Whether actively capturing -- not suspended or stopped."""
618
+ return self ._state == "started"
619
+
616
620
def readouterr (self ) -> CaptureResult [AnyStr ]:
617
621
if self .out :
618
622
out = self .out .snap ()
@@ -757,11 +761,19 @@ def resume_fixture(self) -> None:
757
761
@contextlib .contextmanager
758
762
def global_and_fixture_disabled (self ) -> Generator [None , None , None ]:
759
763
"""Context manager to temporarily disable global and current fixture capturing."""
760
- self .suspend ()
764
+ do_fixture = self ._capture_fixture and self ._capture_fixture ._is_started ()
765
+ if do_fixture :
766
+ self .suspend_fixture ()
767
+ do_global = self ._global_capturing and self ._global_capturing .is_started ()
768
+ if do_global :
769
+ self .suspend_global_capture ()
761
770
try :
762
771
yield
763
772
finally :
764
- self .resume ()
773
+ if do_global :
774
+ self .resume_global_capture ()
775
+ if do_fixture :
776
+ self .resume_fixture ()
765
777
766
778
@contextlib .contextmanager
767
779
def item_capture (self , when : str , item : Item ) -> Generator [None , None , None ]:
@@ -871,6 +883,12 @@ def _resume(self) -> None:
871
883
if self ._capture is not None :
872
884
self ._capture .resume_capturing ()
873
885
886
+ def _is_started (self ) -> bool :
887
+ """Whether actively capturing -- not disabled or closed."""
888
+ if self ._capture is not None :
889
+ return self ._capture .is_started ()
890
+ return False
891
+
874
892
@contextlib .contextmanager
875
893
def disabled (self ) -> Generator [None , None , None ]:
876
894
"""Temporarily disable capturing while inside the ``with`` block."""
0 commit comments