MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_find_parametrized_scope

Method test_find_parametrized_scope

testing/python/metafunc.py:140–191  ·  view source on GitHub ↗

Unit test for _find_parametrized_scope (#3941).

(self)

Source from the content-addressed store, hash-verified

138 metafunc.parametrize("request", [1])
139
140 def test_find_parametrized_scope(self) -> None:
141 """Unit test for _find_parametrized_scope (#3941)."""
142 from _pytest.python import _find_parametrized_scope
143
144 @attr.s
145 class DummyFixtureDef:
146 _scope = attr.ib()
147
148 fixtures_defs = cast(
149 Dict[str, Sequence[fixtures.FixtureDef[object]]],
150 dict(
151 session_fix=[DummyFixtureDef(Scope.Session)],
152 package_fix=[DummyFixtureDef(Scope.Package)],
153 module_fix=[DummyFixtureDef(Scope.Module)],
154 class_fix=[DummyFixtureDef(Scope.Class)],
155 func_fix=[DummyFixtureDef(Scope.Function)],
156 ),
157 )
158
159 # use arguments to determine narrow scope; the cause of the bug is that it would look on all
160 # fixture defs given to the method
161 def find_scope(argnames, indirect):
162 return _find_parametrized_scope(argnames, fixtures_defs, indirect=indirect)
163
164 assert find_scope(["func_fix"], indirect=True) == Scope.Function
165 assert find_scope(["class_fix"], indirect=True) == Scope.Class
166 assert find_scope(["module_fix"], indirect=True) == Scope.Module
167 assert find_scope(["package_fix"], indirect=True) == Scope.Package
168 assert find_scope(["session_fix"], indirect=True) == Scope.Session
169
170 assert find_scope(["class_fix", "func_fix"], indirect=True) == Scope.Function
171 assert find_scope(["func_fix", "session_fix"], indirect=True) == Scope.Function
172 assert find_scope(["session_fix", "class_fix"], indirect=True) == Scope.Class
173 assert (
174 find_scope(["package_fix", "session_fix"], indirect=True) == Scope.Package
175 )
176 assert find_scope(["module_fix", "session_fix"], indirect=True) == Scope.Module
177
178 # when indirect is False or is not for all scopes, always use function
179 assert (
180 find_scope(["session_fix", "module_fix"], indirect=False) == Scope.Function
181 )
182 assert (
183 find_scope(["session_fix", "module_fix"], indirect=["module_fix"])
184 == Scope.Function
185 )
186 assert (
187 find_scope(
188 ["session_fix", "module_fix"], indirect=["session_fix", "module_fix"]
189 )
190 == Scope.Module
191 )
192
193 def test_parametrize_and_id(self) -> None:
194 def func(x, y):

Callers

nothing calls this directly

Calls 1

DummyFixtureDefClass · 0.85

Tested by

no test coverage detected