PR feedback: Make shouldfail and shouldstop properties, prevent True -> False transition

This commit is contained in:
Ben Brown 2024-01-02 11:27:03 -05:00 committed by Ran Benita
parent c1adee097b
commit 75e9f3b19d
1 changed files with 24 additions and 2 deletions

View File

@ -548,8 +548,8 @@ class Session(nodes.Collector):
) )
self.testsfailed = 0 self.testsfailed = 0
self.testscollected = 0 self.testscollected = 0
self.shouldstop: Union[bool, str] = False self._shouldstop: Union[bool, str] = False
self.shouldfail: Union[bool, str] = False self._shouldfail: Union[bool, str] = False
self.trace = config.trace.root.get("collection") self.trace = config.trace.root.get("collection")
self._initialpaths: FrozenSet[Path] = frozenset() self._initialpaths: FrozenSet[Path] = frozenset()
self._initialpaths_with_parents: FrozenSet[Path] = frozenset() self._initialpaths_with_parents: FrozenSet[Path] = frozenset()
@ -576,6 +576,28 @@ class Session(nodes.Collector):
self.testscollected, self.testscollected,
) )
@property
def shouldstop(self) -> Union[bool, str]:
return self._shouldstop
@shouldstop.setter
def shouldstop(self, value: Union[bool, str]) -> None:
"""Prevent plugins from setting this to False once it has been set."""
if value is False and self._shouldstop:
return
self._shouldstop = value
@property
def shouldfail(self) -> Union[bool, str]:
return self._shouldfail
@shouldfail.setter
def shouldfail(self, value: Union[bool, str]) -> None:
"""Prevent plugins from setting this to False once it has been set."""
if value is False and self._shouldfail:
return
self._shouldfail = value
@property @property
def startpath(self) -> Path: def startpath(self) -> Path:
"""The path from which pytest was invoked. """The path from which pytest was invoked.