File tree 3 files changed +16
-3
lines changed 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ New Features
8
8
* Added an ini option ``doctest_encoding `` to specify which encoding to use for doctest files.
9
9
Thanks `@wheerd `_ for the PR (`#2101 `_).
10
10
11
- *
11
+ * ``pytest.warns `` now checks for subclass relationship rather than
12
+ class equality. Thanks `@lesteve `_ for the PR (`#2163 `_)
12
13
13
14
14
15
Changes
@@ -40,13 +41,14 @@ Changes
40
41
.. _@fushi : https://github.com/fushi
41
42
.. _@mattduck : https://github.com/mattduck
42
43
.. _@wheerd : https://github.com/wheerd
44
+ .. _@lesteve : https://github.com/lesteve
43
45
44
46
.. _#1512 : https://github.com/pytest-dev/pytest/issues/1512
45
47
.. _#1874 : https://github.com/pytest-dev/pytest/pull/1874
46
48
.. _#1952 : https://github.com/pytest-dev/pytest/pull/1952
47
49
.. _#2013 : https://github.com/pytest-dev/pytest/issues/2013
48
50
.. _#2101 : https://github.com/pytest-dev/pytest/pull/2101
49
-
51
+ .. _ #2164 : https://github.com/pytest-dev/pytest/pull/2164
50
52
51
53
3.0.5.dev0
52
54
==========
Original file line number Diff line number Diff line change @@ -216,6 +216,7 @@ def __exit__(self, *exc_info):
216
216
# only check if we're not currently handling an exception
217
217
if all (a is None for a in exc_info ):
218
218
if self .expected_warning is not None :
219
- if not any (r .category in self .expected_warning for r in self ):
219
+ if not any (issubclass (r .category , exp_warning ) for
220
+ exp_warning in self .expected_warning for r in self ):
220
221
__tracebackhide__ = True
221
222
pytest .fail ("DID NOT WARN" )
Original file line number Diff line number Diff line change @@ -215,6 +215,16 @@ def test_record_only(self):
215
215
assert str (record [0 ].message ) == "user"
216
216
assert str (record [1 ].message ) == "runtime"
217
217
218
+ def test_record_by_subclass (self ):
219
+ with pytest .warns (Warning ) as record :
220
+ warnings .warn ("user" , UserWarning )
221
+ warnings .warn ("runtime" , RuntimeWarning )
222
+
223
+ assert len (record ) == 2
224
+ assert str (record [0 ].message ) == "user"
225
+ assert str (record [1 ].message ) == "runtime"
226
+
227
+
218
228
def test_double_test (self , testdir ):
219
229
"""If a test is run again, the warning should still be raised"""
220
230
testdir .makepyfile ('''
You can’t perform that action at this time.
0 commit comments