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

Method test_deprecated_call_modes

testing/test_recwarn.py:158–174  ·  view source on GitHub ↗

Ensure deprecated_call() captures a deprecation warning as expected inside its block/function.

(self, warning_type, mode, call_f_first)

Source from the content-addressed store, hash-verified

156 @pytest.mark.parametrize("call_f_first", [True, False])
157 @pytest.mark.filterwarnings("ignore")
158 def test_deprecated_call_modes(self, warning_type, mode, call_f_first) -> None:
159 """Ensure deprecated_call() captures a deprecation warning as expected inside its
160 block/function.
161 """
162
163 def f():
164 warnings.warn(warning_type("hi"))
165 return 10
166
167 # ensure deprecated_call() can capture the warning even if it has already been triggered
168 if call_f_first:
169 assert f() == 10
170 if mode == "call":
171 assert pytest.deprecated_call(f) == 10
172 else:
173 with pytest.deprecated_call():
174 assert f() == 10
175
176 @pytest.mark.parametrize("mode", ["context_manager", "call"])
177 def test_deprecated_call_exception_is_raised(self, mode) -> None:

Callers

nothing calls this directly

Calls 1

fFunction · 0.70

Tested by

no test coverage detected