PHP 8.2.30
Preview: scope.py Size: 2.81 KB
//opt/cloudlinux/venv/lib/python3.11/site-packages/_pytest/scope.py

"""
Scope definition and related utilities.

Those are defined here, instead of in the 'fixtures' module because
their use is spread across many other pytest modules, and centralizing it in 'fixtures'
would cause circular references.

Also this makes the module light to import, as it should.
"""
from enum import Enum
from functools import total_ordering
from typing import Optional
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from typing_extensions import Literal

    _ScopeName = Literal["session", "package", "module", "class", "function"]


@total_ordering
class Scope(Enum):
    """
    Represents one of the possible fixture scopes in pytest.

    Scopes are ordered from lower to higher, that is:

              ->>> higher ->>>

    Function < Class < Module < Package < Session

              <<<- lower  <<<-
    """

    # Scopes need to be listed from lower to higher.
    Function: "_ScopeName" = "function"
    Class: "_ScopeName" = "class"
    Module: "_ScopeName" = "module"
    Package: "_ScopeName" = "package"
    Session: "_ScopeName" = "session"

    def next_lower(self) -> "Scope":
        """Return the next lower scope."""
        index = _SCOPE_INDICES[self]
        if index == 0:
            raise ValueError(f"{self} is the lower-most scope")
        return _ALL_SCOPES[index - 1]

    def next_higher(self) -> "Scope":
        """Return the next higher scope."""
        index = _SCOPE_INDICES[self]
        if index == len(_SCOPE_INDICES) - 1:
            raise ValueError(f"{self} is the upper-most scope")
        return _ALL_SCOPES[index + 1]

    def __lt__(self, other: "Scope") -> bool:
        self_index = _SCOPE_INDICES[self]
        other_index = _SCOPE_INDICES[other]
        return self_index < other_index

    @classmethod
    def from_user(
        cls, scope_name: "_ScopeName", descr: str, where: Optional[str] = None
    ) -> "Scope":
        """
        Given a scope name from the user, return the equivalent Scope enum. Should be used
        whenever we want to convert a user provided scope name to its enum object.

        If the scope name is invalid, construct a user friendly message and call pytest.fail.
        """
        from _pytest.outcomes import fail

        try:
            # Holding this reference is necessary for mypy at the moment.
            scope = Scope(scope_name)
        except ValueError:
            fail(
                "{} {}got an unexpected scope value '{}'".format(
                    descr, f"from {where} " if where else "", scope_name
                ),
                pytrace=False,
            )
        return scope


_ALL_SCOPES = list(Scope)
_SCOPE_INDICES = {scope: index for index, scope in enumerate(_ALL_SCOPES)}


# Ordered list of scopes which can contain many tests (in practice all except Function).
HIGH_SCOPES = [x for x in Scope if x is not Scope.Function]

Directory Contents

Dirs: 7 × Files: 47

Name Size Perms Modified Actions
assertion DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
config DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
mark DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
_code DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
_io DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
_py DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
20.89 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
33.92 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
12.89 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
13.18 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.36 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
25.35 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.04 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
65.51 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.31 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
8.34 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
31.79 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
25.11 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
16.53 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
33.23 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
31.73 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
14.51 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
25.94 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.65 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
10.02 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.86 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
25.22 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
0 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
60.52 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.27 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
69.49 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
37.50 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
709 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
10.67 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
20.35 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
18.01 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.81 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.18 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.19 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
9.96 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.98 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.60 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
52.25 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.85 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
375 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
11.43 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
14.46 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.12 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.95 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.37 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.71 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
160 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
356 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).