File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change
1
+ Stack level for ``FutureWarning `` updated to level 2.
Original file line number Diff line number Diff line change @@ -357,10 +357,8 @@ def formatwarning(
357
357
# try to set useful defaults for the most common warning categories
358
358
if category == DeprecationWarning :
359
359
kwargs ["stacklevel" ] = 3
360
- elif category == UserWarning :
360
+ elif category in ( UserWarning , FutureWarning ) :
361
361
kwargs ["stacklevel" ] = 2
362
- elif category == FutureWarning :
363
- kwargs ["stacklevel" ] = 3
364
362
365
363
warnings .formatwarning = formatwarning
366
364
warnings .warn (message , category = category , ** kwargs )
Original file line number Diff line number Diff line change @@ -12,14 +12,22 @@ def test_sort_dicts_by_keys():
12
12
assert actual == expected
13
13
14
14
15
- def test_raise_warning ():
15
+ def test_raise_user_warning ():
16
16
with pytest .warns (UserWarning ) as record :
17
17
raise_warning ("My warning." )
18
18
19
19
assert len (record ) == 1
20
20
assert record [0 ].message .args [0 ] == "My warning."
21
21
22
22
23
+ def test_raise_future_warning ():
24
+ with pytest .warns (FutureWarning ) as record :
25
+ raise_warning ("My future warning." , FutureWarning )
26
+
27
+ assert len (record ) == 1
28
+ assert record [0 ].message .args [0 ] == "My future warning."
29
+
30
+
23
31
def test_raise_deprecation ():
24
32
with pytest .warns (DeprecationWarning ) as record :
25
33
raise_warning ("My warning." , DeprecationWarning )
You can’t perform that action at this time.
0 commit comments