From babbff4b9366799c2044d4f282aa22a10d481221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Thu, 29 Dec 2016 09:34:21 +0100 Subject: [PATCH] Add a test with custom classes --- testing/test_recwarn.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index ef2ebd74cb4..3a50c14348b 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -247,6 +247,17 @@ def test_record_by_subclass(self): assert str(record[0].message) == "user" assert str(record[1].message) == "runtime" + class MyUserWarning1(UserWarning): pass + class MyUserWarning2(UserWarning): pass + + with pytest.warns(UserWarning) as record: + warnings.warn("user 1", MyUserWarning1) + warnings.warn("user 2", MyUserWarning2) + + assert len(record) == 2 + assert str(record[0].message) == "user 1" + assert str(record[1].message) == "user 2" + def test_double_test(self, testdir): """If a test is run again, the warning should still be raised"""