@@ -20,8 +20,8 @@ def pyfile_with_warnings(testdir, request):
20
20
module_name : '''
21
21
import warnings
22
22
def foo():
23
- warnings.warn(PendingDeprecationWarning("functionality is pending deprecation "))
24
- warnings.warn(DeprecationWarning("functionality is deprecated "))
23
+ warnings.warn(UserWarning("user warning "))
24
+ warnings.warn(RuntimeWarning("runtime warning "))
25
25
return 1
26
26
''' ,
27
27
test_name : '''
@@ -43,11 +43,11 @@ def test_normal_flow(testdir, pyfile_with_warnings):
43
43
44
44
'*test_normal_flow.py::test_func' ,
45
45
46
- '*normal_flow_module.py:3: PendingDeprecationWarning: functionality is pending deprecation ' ,
47
- '* warnings.warn(PendingDeprecationWarning("functionality is pending deprecation "))' ,
46
+ '*normal_flow_module.py:3: UserWarning: user warning ' ,
47
+ '* warnings.warn(UserWarning("user warning "))' ,
48
48
49
- '*normal_flow_module.py:4: DeprecationWarning: functionality is deprecated ' ,
50
- '* warnings.warn(DeprecationWarning("functionality is deprecated "))' ,
49
+ '*normal_flow_module.py:4: RuntimeWarning: runtime warning ' ,
50
+ '* warnings.warn(RuntimeWarning("runtime warning "))' ,
51
51
'* 1 passed, 2 warnings*' ,
52
52
])
53
53
assert result .stdout .str ().count ('test_normal_flow.py::test_func' ) == 1
@@ -90,8 +90,8 @@ def test_as_errors(testdir, pyfile_with_warnings, method):
90
90
''' )
91
91
result = testdir .runpytest (* args )
92
92
result .stdout .fnmatch_lines ([
93
- 'E PendingDeprecationWarning: functionality is pending deprecation ' ,
94
- 'as_errors_module.py:3: PendingDeprecationWarning ' ,
93
+ 'E UserWarning: user warning ' ,
94
+ 'as_errors_module.py:3: UserWarning ' ,
95
95
'* 1 failed in *' ,
96
96
])
97
97
@@ -133,9 +133,7 @@ def test_func(fix):
133
133
result = testdir .runpytest ()
134
134
result .stdout .fnmatch_lines ([
135
135
'*== %s ==*' % WARNINGS_SUMMARY_HEADER ,
136
-
137
- '*test_unicode.py:8: UserWarning: \u6d4b \u8bd5 ' ,
138
- '*warnings.warn(u"\u6d4b \u8bd5 ")' ,
136
+ '*test_unicode.py:8: UserWarning: \u6d4b \u8bd5 *' ,
139
137
'* 1 passed, 1 warnings*' ,
140
138
])
141
139
@@ -163,6 +161,30 @@ def test_func(fix):
163
161
164
162
'*test_py2_unicode.py:8: UserWarning: \u6d4b \u8bd5 ' ,
165
163
'*warnings.warn(u"\u6d4b \u8bd5 ")' ,
166
- '*warnings.py:82 : UnicodeWarning: This warning*\u6d4b \u8bd5 ' ,
164
+ '*warnings.py:* : UnicodeWarning: This warning*\u6d4b \u8bd5 ' ,
167
165
'* 1 passed, 2 warnings*' ,
168
166
])
167
+
168
+
169
+ def test_works_with_filterwarnings (testdir ):
170
+ """Ensure our warnings capture does not mess with pre-installed filters (#2430)."""
171
+ testdir .makepyfile ('''
172
+ import warnings
173
+
174
+ class MyWarning(Warning):
175
+ pass
176
+
177
+ warnings.filterwarnings("error", category=MyWarning)
178
+
179
+ class TestWarnings(object):
180
+ def test_my_warning(self):
181
+ try:
182
+ warnings.warn(MyWarning("warn!"))
183
+ assert False
184
+ except MyWarning:
185
+ assert True
186
+ ''' )
187
+ result = testdir .runpytest ()
188
+ result .stdout .fnmatch_lines ([
189
+ '*== 1 passed in *' ,
190
+ ])
0 commit comments