MCPcopy
hub / github.com/pytest-dev/pytest / from_user

Method from_user

src/_pytest/scope.py:62–83  ·  view source on GitHub ↗

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.

(
        cls, scope_name: ScopeName, descr: str, where: str | None = None
    )

Source from the content-addressed store, hash-verified

60
61 @classmethod
62 def from_user(
63 cls, scope_name: ScopeName, descr: str, where: str | None = None
64 ) -> Scope:
65 """
66 Given a scope name from the user, return the equivalent Scope enum. Should be used
67 whenever we want to convert a user provided scope name to its enum object.
68
69 If the scope name is invalid, construct a user friendly message and call pytest.fail.
70 """
71 from _pytest.outcomes import fail
72
73 try:
74 # Holding this reference is necessary for mypy at the moment.
75 scope = Scope(scope_name)
76 except ValueError:
77 fail(
78 "{} {}got an unexpected scope value '{}'".format(
79 descr, f"from {where} " if where else "", scope_name
80 ),
81 pytrace=False,
82 )
83 return scope
84
85
86_ALL_SCOPES = list(Scope)

Callers 3

parametrizeMethod · 0.80
__init__Method · 0.80
test_from_userFunction · 0.80

Calls 2

ScopeClass · 0.85
formatMethod · 0.45

Tested by 1

test_from_userFunction · 0.64