Skip to content

Commit babbff4

Browse files
committed
Add a test with custom classes
1 parent 6173120 commit babbff4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

testing/test_recwarn.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,17 @@ def test_record_by_subclass(self):
247247
assert str(record[0].message) == "user"
248248
assert str(record[1].message) == "runtime"
249249

250+
class MyUserWarning1(UserWarning): pass
251+
class MyUserWarning2(UserWarning): pass
252+
253+
with pytest.warns(UserWarning) as record:
254+
warnings.warn("user 1", MyUserWarning1)
255+
warnings.warn("user 2", MyUserWarning2)
256+
257+
assert len(record) == 2
258+
assert str(record[0].message) == "user 1"
259+
assert str(record[1].message) == "user 2"
260+
250261

251262
def test_double_test(self, testdir):
252263
"""If a test is run again, the warning should still be raised"""

0 commit comments

Comments
 (0)