Skip to content

Commit

Permalink
tests: harden testing/test_recwarn.py::TestWarningsRecorderChecker::t…
Browse files Browse the repository at this point in the history
…est_typechecking (regressed in 2dca68)
  • Loading branch information
blueyed committed Oct 2, 2020
1 parent afa9cd0 commit 624028e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions testing/test_recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Optional

import pytest
from _pytest.recwarn import WarningsChecker
from _pytest.recwarn import WarningsRecorder


Expand Down Expand Up @@ -50,14 +51,13 @@ def test_warn_stacklevel(self) -> None:
warnings.warn("test", DeprecationWarning, 2)

def test_typechecking(self) -> None:
from _pytest.recwarn import WarningsChecker

with pytest.raises(TypeError):
WarningsChecker(5) # type: ignore
with pytest.raises(TypeError):
WarningsChecker(("hi", RuntimeWarning)) # type: ignore
with pytest.raises(TypeError):
WarningsChecker([DeprecationWarning, RuntimeWarning]) # type: ignore
msg = "exceptions must be derived from Warning, not <class '{}'>"
with pytest.raises(TypeError, match=msg.format("int")):
WarningsChecker(5)
with pytest.raises(TypeError, match=msg.format("str")):
WarningsChecker(("hi", RuntimeWarning))
with pytest.raises(TypeError, match=msg.format("list")):
WarningsChecker([DeprecationWarning, RuntimeWarning])

def test_invalid_enter_exit(self) -> None:
# wrap this test in WarningsRecorder to ensure warning state gets reset
Expand Down

0 comments on commit 624028e

Please sign in to comment.