In python2, display previously warned warnings

This commit is contained in:
Anthony Sottile
2018-10-10 09:36:19 -07:00
parent aeb92accb2
commit e0f6fce9e9
3 changed files with 24 additions and 0 deletions
+10
View File
@@ -350,3 +350,13 @@ class TestWarns(object):
with pytest.warns(UserWarning, match=r"aaa"):
warnings.warn("bbbbbbbbbb", UserWarning)
warnings.warn("cccccccccc", UserWarning)
@pytest.mark.filterwarnings("ignore")
def test_can_capture_previously_warned(self):
def f():
warnings.warn(UserWarning("ohai"))
return 10
assert f() == 10
assert pytest.warns(UserWarning, f) == 10
assert pytest.warns(UserWarning, f) == 10