@@ -172,22 +172,6 @@ def f():
172
172
with pytest .deprecated_call ():
173
173
assert f () == 10
174
174
175
- @pytest .mark .parametrize ("mode" , ["context_manager" , "call" ])
176
- def test_deprecated_call_exception_is_raised (self , mode ) -> None :
177
- """If the block of the code being tested by deprecated_call() raises an exception,
178
- it must raise the exception undisturbed.
179
- """
180
-
181
- def f ():
182
- raise ValueError ("some exception" )
183
-
184
- with pytest .raises (ValueError , match = "some exception" ):
185
- if mode == "call" :
186
- pytest .deprecated_call (f )
187
- else :
188
- with pytest .deprecated_call ():
189
- f ()
190
-
191
175
def test_deprecated_call_specificity (self ) -> None :
192
176
other_warnings = [
193
177
Warning ,
@@ -446,3 +430,15 @@ def test_re_emit_non_match_single(self) -> None:
446
430
with pytest .warns (UserWarning , match = "v1 warning" ):
447
431
warnings .warn ("v1 warning" , UserWarning )
448
432
warnings .warn ("non-matching v2 warning" , UserWarning )
433
+
434
+ def test_catch_warning_within_raise (self ) -> None :
435
+ # warns-in-raises works since https://github.com/pytest-dev/pytest/pull/11129
436
+ with pytest .raises (ValueError , match = "some exception" ):
437
+ with pytest .warns (FutureWarning , match = "some warning" ):
438
+ warnings .warn ("some warning" , category = FutureWarning )
439
+ raise ValueError ("some exception" )
440
+ # and raises-in-warns has always worked but we'll check for symmetry.
441
+ with pytest .warns (FutureWarning , match = "some warning" ):
442
+ with pytest .raises (ValueError , match = "some exception" ):
443
+ warnings .warn ("some warning" , category = FutureWarning )
444
+ raise ValueError ("some exception" )
0 commit comments