6
6
import importlib
7
7
import os
8
8
import sys
9
+ import warnings
9
10
from pathlib import Path
10
11
from typing import AbstractSet
11
12
from typing import Callable
45
46
from _pytest .reports import TestReport
46
47
from _pytest .runner import collect_one_node
47
48
from _pytest .runner import SetupState
49
+ from _pytest .warning_types import PytestWarning
48
50
49
51
50
52
def pytest_addoption (parser : Parser ) -> None :
@@ -550,8 +552,8 @@ def __init__(self, config: Config) -> None:
550
552
)
551
553
self .testsfailed = 0
552
554
self .testscollected = 0
553
- self .shouldstop : Union [bool , str ] = False
554
- self .shouldfail : Union [bool , str ] = False
555
+ self ._shouldstop : Union [bool , str ] = False
556
+ self ._shouldfail : Union [bool , str ] = False
555
557
self .trace = config .trace .root .get ("collection" )
556
558
self ._initialpaths : FrozenSet [Path ] = frozenset ()
557
559
self ._initialpaths_with_parents : FrozenSet [Path ] = frozenset ()
@@ -578,6 +580,42 @@ def __repr__(self) -> str:
578
580
self .testscollected ,
579
581
)
580
582
583
+ @property
584
+ def shouldstop (self ) -> Union [bool , str ]:
585
+ return self ._shouldstop
586
+
587
+ @shouldstop .setter
588
+ def shouldstop (self , value : Union [bool , str ]) -> None :
589
+ # The runner checks shouldfail and assumes that if it is set we are
590
+ # definitely stopping, so prevent unsetting it.
591
+ if value is False and self ._shouldstop :
592
+ warnings .warn (
593
+ PytestWarning (
594
+ "session.shouldstop cannot be unset after it has been set; ignoring."
595
+ ),
596
+ stacklevel = 2 ,
597
+ )
598
+ return
599
+ self ._shouldstop = value
600
+
601
+ @property
602
+ def shouldfail (self ) -> Union [bool , str ]:
603
+ return self ._shouldfail
604
+
605
+ @shouldfail .setter
606
+ def shouldfail (self , value : Union [bool , str ]) -> None :
607
+ # The runner checks shouldfail and assumes that if it is set we are
608
+ # definitely stopping, so prevent unsetting it.
609
+ if value is False and self ._shouldfail :
610
+ warnings .warn (
611
+ PytestWarning (
612
+ "session.shouldfail cannot be unset after it has been set; ignoring."
613
+ ),
614
+ stacklevel = 2 ,
615
+ )
616
+ return
617
+ self ._shouldfail = value
618
+
581
619
@property
582
620
def startpath (self ) -> Path :
583
621
"""The path from which pytest was invoked.
0 commit comments