/opt/cloudlinux/venv/lib/python3.11/site-packages/_pytest
NameSizeModeActions
assertion/-0755rm
config/-0755rm
mark/-0755rm
_code/-0755rm
_io/-0755rm
_py/-0755rm
__pycache__/-0755rm
cacheprovider.py213920644editdlrm
capture.py347370644editdlrm
compat.py132000644editdlrm
debugging.py134980644editdlrm
deprecated.py54870644editdlrm
doctest.py259610644editdlrm
faulthandler.py31140644editdlrm
fixtures.py670850644editdlrm
freeze_support.py13390644editdlrm
helpconfig.py85380644editdlrm
hookspec.py325580644editdlrm
junitxml.py257160644editdlrm
legacypath.py169290644editdlrm
logging.py340310644editdlrm
main.py324910644editdlrm
monkeypatch.py148570644editdlrm
nodes.py265590644editdlrm
nose.py16880644editdlrm
outcomes.py102560644editdlrm
pastebin.py39490644editdlrm
pathlib.py258240644editdlrm
py.typed00644editdlrm
pytester.py619710644editdlrm
pytester_assertions.py23270644editdlrm
python.py711550644editdlrm
python_api.py384000644editdlrm
python_path.py7090644editdlrm
recwarn.py109300644editdlrm
reports.py208400644editdlrm
runner.py184470644editdlrm
scope.py28820644editdlrm
setuponly.py32610644editdlrm
setupplan.py12140644editdlrm
skipping.py102000644editdlrm
stash.py30550644editdlrm
stepwise.py47140644editdlrm
terminal.py535090644editdlrm
threadexception.py29150644editdlrm
timing.py3750644editdlrm
tmpdir.py117080644editdlrm
unittest.py148090644editdlrm
unraisableexception.py31910644editdlrm
warnings.py50700644editdlrm
warning_types.py44740644editdlrm
_argcomplete.py37940644editdlrm
_version.py1600644editdlrm
__init__.py3560644editdlrm
Edit: /opt/cloudlinux/venv/lib/python3.11/site-packages/_pytest/stash.py (3055B)
from typing import Any from typing import cast from typing import Dict from typing import Generic from typing import TypeVar from typing import Union __all__ = ["Stash", "StashKey"] T = TypeVar("T") D = TypeVar("D") class StashKey(Generic[T]): """``StashKey`` is an object used as a key to a :class:`Stash`. A ``StashKey`` is associated with the type ``T`` of the value of the key. A ``StashKey`` is unique and cannot conflict with another key. """ __slots__ = () class Stash: r"""``Stash`` is a type-safe heterogeneous mutable mapping that allows keys and value types to be defined separately from where it (the ``Stash``) is created. Usually you will be given an object which has a ``Stash``, for example :class:`~pytest.Config` or a :class:`~_pytest.nodes.Node`: .. code-block:: python stash: Stash = some_object.stash If a module or plugin wants to store data in this ``Stash``, it creates :class:`StashKey`\s for its keys (at the module level): .. code-block:: python # At the top-level of the module some_str_key = StashKey[str]() some_bool_key = StashKey[bool]() To store information: .. code-block:: python # Value type must match the key. stash[some_str_key] = "value" stash[some_bool_key] = True To retrieve the information: .. code-block:: python # The static type of some_str is str. some_str = stash[some_str_key] # The static type of some_bool is bool. some_bool = stash[some_bool_key] """ __slots__ = ("_storage",) def __init__(self) -> None: self._storage: Dict[StashKey[Any], object] = {} def __setitem__(self, key: StashKey[T], value: T) -> None: """Set a value for key.""" self._storage[key] = value def __getitem__(self, key: StashKey[T]) -> T: """Get the value for key. Raises ``KeyError`` if the key wasn't set before. """ return cast(T, self._storage[key]) def get(self, key: StashKey[T], default: D) -> Union[T, D]: """Get the value for key, or return default if the key wasn't set before.""" try: return self[key] except KeyError: return default def setdefault(self, key: StashKey[T], default: T) -> T: """Return the value of key if already set, otherwise set the value of key to default and return default.""" try: return self[key] except KeyError: self[key] = default return default def __delitem__(self, key: StashKey[T]) -> None: """Delete the value for key. Raises ``KeyError`` if the key wasn't set before. """ del self._storage[key] def __contains__(self, key: StashKey[T]) -> bool: """Return whether key was set.""" return key in self._storage def __len__(self) -> int: """Return how many items exist in the stash.""" return len(self._storage)