File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ New Features
88* Added an ini option ``doctest_encoding `` to specify which encoding to use for doctest files.
99 Thanks `@wheerd `_ for the PR (`#2101 `_).
1010
11- *
11+ * ``pytest.warns `` now checks for subclass relationship rather than
12+ class equality. Thanks `@lesteve `_ for the PR (`#2166 `_)
1213
1314
1415Changes
@@ -40,13 +41,14 @@ Changes
4041.. _@fushi : https://github.com/fushi
4142.. _@mattduck : https://github.com/mattduck
4243.. _@wheerd : https://github.com/wheerd
44+ .. _@lesteve : https://github.com/lesteve
4345
4446.. _#1512 : https://github.com/pytest-dev/pytest/issues/1512
4547.. _#1874 : https://github.com/pytest-dev/pytest/pull/1874
4648.. _#1952 : https://github.com/pytest-dev/pytest/pull/1952
4749.. _#2013 : https://github.com/pytest-dev/pytest/issues/2013
4850.. _#2101 : https://github.com/pytest-dev/pytest/pull/2101
49-
51+ .. _ #2166 : https://github.com/pytest-dev/pytest/pull/2166
5052
51533.0.5.dev0
5254==========
Original file line number Diff line number Diff line change @@ -216,6 +216,7 @@ def __exit__(self, *exc_info):
216216 # only check if we're not currently handling an exception
217217 if all (a is None for a in exc_info ):
218218 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 ):
220221 __tracebackhide__ = True
221222 pytest .fail ("DID NOT WARN" )
Original file line number Diff line number Diff line change @@ -215,6 +215,16 @@ def test_record_only(self):
215215 assert str (record [0 ].message ) == "user"
216216 assert str (record [1 ].message ) == "runtime"
217217
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+
218228 def test_double_test (self , testdir ):
219229 """If a test is run again, the warning should still be raised"""
220230 testdir .makepyfile ('''
You can’t perform that action at this time.
0 commit comments