Merge pull request #5593 from bluetech/type-annotations-1

Type-annotate pytest.{exit,skip,fail,xfail,importorskip,warns,raises}
This commit is contained in:
Ran Benita
2019-07-16 22:38:20 +03:00
committed by GitHub
8 changed files with 306 additions and 89 deletions

View File

@@ -58,7 +58,7 @@ class TWMock:
fullwidth = 80
def test_excinfo_simple():
def test_excinfo_simple() -> None:
try:
raise ValueError
except ValueError:
@@ -66,6 +66,14 @@ def test_excinfo_simple():
assert info.type == ValueError
def test_excinfo_from_exc_info_simple():
try:
raise ValueError
except ValueError as e:
info = _pytest._code.ExceptionInfo.from_exc_info((type(e), e, e.__traceback__))
assert info.type == ValueError
def test_excinfo_getstatement():
def g():
raise ValueError

View File

@@ -248,3 +248,9 @@ class TestRaises:
with pytest.raises(CrappyClass()):
pass
assert "via __class__" in excinfo.value.args[0]
def test_raises_context_manager_with_kwargs(self):
with pytest.raises(TypeError) as excinfo:
with pytest.raises(Exception, foo="bar"):
pass
assert "Unexpected keyword arguments" in str(excinfo.value)

View File

@@ -374,3 +374,9 @@ class TestWarns:
assert f() == 10
assert pytest.warns(UserWarning, f) == 10
assert pytest.warns(UserWarning, f) == 10
def test_warns_context_manager_with_kwargs(self):
with pytest.raises(TypeError) as excinfo:
with pytest.warns(UserWarning, foo="bar"):
pass
assert "Unexpected keyword arguments" in str(excinfo.value)