Enable check_untyped_defs mypy option for testing/ too
This commit is contained in:
@@ -428,10 +428,11 @@ class TestApprox:
|
||||
assert a12 != approx(a21)
|
||||
assert a21 != approx(a12)
|
||||
|
||||
def test_doctests(self, mocked_doctest_runner):
|
||||
def test_doctests(self, mocked_doctest_runner) -> None:
|
||||
import doctest
|
||||
|
||||
parser = doctest.DocTestParser()
|
||||
assert approx.__doc__ is not None
|
||||
test = parser.get_doctest(
|
||||
approx.__doc__, {"approx": approx}, approx.__name__, None, None
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
|
||||
import _pytest._code
|
||||
import pytest
|
||||
@@ -698,7 +700,7 @@ class TestFunction:
|
||||
|
||||
|
||||
class TestSorting:
|
||||
def test_check_equality(self, testdir):
|
||||
def test_check_equality(self, testdir) -> None:
|
||||
modcol = testdir.getmodulecol(
|
||||
"""
|
||||
def test_pass(): pass
|
||||
@@ -720,10 +722,10 @@ class TestSorting:
|
||||
assert fn1 != fn3
|
||||
|
||||
for fn in fn1, fn2, fn3:
|
||||
assert fn != 3
|
||||
assert fn != 3 # type: ignore[comparison-overlap] # noqa: F821
|
||||
assert fn != modcol
|
||||
assert fn != [1, 2, 3]
|
||||
assert [1, 2, 3] != fn
|
||||
assert fn != [1, 2, 3] # type: ignore[comparison-overlap] # noqa: F821
|
||||
assert [1, 2, 3] != fn # type: ignore[comparison-overlap] # noqa: F821
|
||||
assert modcol != fn
|
||||
|
||||
def test_allow_sane_sorting_for_decorators(self, testdir):
|
||||
@@ -1006,7 +1008,7 @@ class TestTracebackCutting:
|
||||
assert "INTERNALERROR>" not in out
|
||||
result.stdout.fnmatch_lines(["*ValueError: fail me*", "* 1 error in *"])
|
||||
|
||||
def test_filter_traceback_generated_code(self):
|
||||
def test_filter_traceback_generated_code(self) -> None:
|
||||
"""test that filter_traceback() works with the fact that
|
||||
_pytest._code.code.Code.path attribute might return an str object.
|
||||
In this case, one of the entries on the traceback was produced by
|
||||
@@ -1017,17 +1019,18 @@ class TestTracebackCutting:
|
||||
from _pytest.python import filter_traceback
|
||||
|
||||
try:
|
||||
ns = {}
|
||||
ns = {} # type: Dict[str, Any]
|
||||
exec("def foo(): raise ValueError", ns)
|
||||
ns["foo"]()
|
||||
except ValueError:
|
||||
_, _, tb = sys.exc_info()
|
||||
|
||||
tb = _pytest._code.Traceback(tb)
|
||||
assert isinstance(tb[-1].path, str)
|
||||
assert not filter_traceback(tb[-1])
|
||||
assert tb is not None
|
||||
traceback = _pytest._code.Traceback(tb)
|
||||
assert isinstance(traceback[-1].path, str)
|
||||
assert not filter_traceback(traceback[-1])
|
||||
|
||||
def test_filter_traceback_path_no_longer_valid(self, testdir):
|
||||
def test_filter_traceback_path_no_longer_valid(self, testdir) -> None:
|
||||
"""test that filter_traceback() works with the fact that
|
||||
_pytest._code.code.Code.path attribute might return an str object.
|
||||
In this case, one of the files in the traceback no longer exists.
|
||||
@@ -1049,10 +1052,11 @@ class TestTracebackCutting:
|
||||
except ValueError:
|
||||
_, _, tb = sys.exc_info()
|
||||
|
||||
assert tb is not None
|
||||
testdir.tmpdir.join("filter_traceback_entry_as_str.py").remove()
|
||||
tb = _pytest._code.Traceback(tb)
|
||||
assert isinstance(tb[-1].path, str)
|
||||
assert filter_traceback(tb[-1])
|
||||
traceback = _pytest._code.Traceback(tb)
|
||||
assert isinstance(traceback[-1].path, str)
|
||||
assert filter_traceback(traceback[-1])
|
||||
|
||||
|
||||
class TestReportInfo:
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from _pytest import python
|
||||
from _pytest import runner
|
||||
|
||||
|
||||
class TestOEJSKITSpecials:
|
||||
def test_funcarg_non_pycollectobj(self, testdir, recwarn): # rough jstests usage
|
||||
def test_funcarg_non_pycollectobj(
|
||||
self, testdir, recwarn
|
||||
) -> None: # rough jstests usage
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
@@ -28,13 +32,14 @@ class TestOEJSKITSpecials:
|
||||
)
|
||||
# this hook finds funcarg factories
|
||||
rep = runner.collect_one_node(collector=modcol)
|
||||
clscol = rep.result[0]
|
||||
# TODO: Don't treat as Any.
|
||||
clscol = rep.result[0] # type: Any
|
||||
clscol.obj = lambda arg1: None
|
||||
clscol.funcargs = {}
|
||||
pytest._fillfuncargs(clscol)
|
||||
assert clscol.funcargs["arg1"] == 42
|
||||
|
||||
def test_autouse_fixture(self, testdir, recwarn): # rough jstests usage
|
||||
def test_autouse_fixture(self, testdir, recwarn) -> None: # rough jstests usage
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
@@ -61,20 +66,21 @@ class TestOEJSKITSpecials:
|
||||
)
|
||||
# this hook finds funcarg factories
|
||||
rep = runner.collect_one_node(modcol)
|
||||
clscol = rep.result[0]
|
||||
# TODO: Don't treat as Any.
|
||||
clscol = rep.result[0] # type: Any
|
||||
clscol.obj = lambda: None
|
||||
clscol.funcargs = {}
|
||||
pytest._fillfuncargs(clscol)
|
||||
assert not clscol.funcargs
|
||||
|
||||
|
||||
def test_wrapped_getfslineno():
|
||||
def test_wrapped_getfslineno() -> None:
|
||||
def func():
|
||||
pass
|
||||
|
||||
def wrap(f):
|
||||
func.__wrapped__ = f
|
||||
func.patchings = ["qwe"]
|
||||
func.__wrapped__ = f # type: ignore
|
||||
func.patchings = ["qwe"] # type: ignore
|
||||
return func
|
||||
|
||||
@wrap
|
||||
@@ -87,14 +93,14 @@ def test_wrapped_getfslineno():
|
||||
|
||||
|
||||
class TestMockDecoration:
|
||||
def test_wrapped_getfuncargnames(self):
|
||||
def test_wrapped_getfuncargnames(self) -> None:
|
||||
from _pytest.compat import getfuncargnames
|
||||
|
||||
def wrap(f):
|
||||
def func():
|
||||
pass
|
||||
|
||||
func.__wrapped__ = f
|
||||
func.__wrapped__ = f # type: ignore
|
||||
return func
|
||||
|
||||
@wrap
|
||||
@@ -322,10 +328,11 @@ class TestReRunTests:
|
||||
)
|
||||
|
||||
|
||||
def test_pytestconfig_is_session_scoped():
|
||||
def test_pytestconfig_is_session_scoped() -> None:
|
||||
from _pytest.fixtures import pytestconfig
|
||||
|
||||
assert pytestconfig._pytestfixturefunction.scope == "session"
|
||||
marker = pytestconfig._pytestfixturefunction # type: ignore
|
||||
assert marker.scope == "session"
|
||||
|
||||
|
||||
class TestNoselikeTestAttribute:
|
||||
|
||||
@@ -6,9 +6,9 @@ from _pytest.outcomes import Failed
|
||||
|
||||
|
||||
class TestRaises:
|
||||
def test_check_callable(self):
|
||||
def test_check_callable(self) -> None:
|
||||
with pytest.raises(TypeError, match=r".* must be callable"):
|
||||
pytest.raises(RuntimeError, "int('qwe')")
|
||||
pytest.raises(RuntimeError, "int('qwe')") # type: ignore[call-overload] # noqa: F821
|
||||
|
||||
def test_raises(self):
|
||||
excinfo = pytest.raises(ValueError, int, "qwe")
|
||||
@@ -18,19 +18,19 @@ class TestRaises:
|
||||
excinfo = pytest.raises(ValueError, int, "hello")
|
||||
assert "invalid literal" in str(excinfo.value)
|
||||
|
||||
def test_raises_callable_no_exception(self):
|
||||
def test_raises_callable_no_exception(self) -> None:
|
||||
class A:
|
||||
def __call__(self):
|
||||
pass
|
||||
|
||||
try:
|
||||
pytest.raises(ValueError, A())
|
||||
except pytest.raises.Exception:
|
||||
except pytest.fail.Exception:
|
||||
pass
|
||||
|
||||
def test_raises_falsey_type_error(self):
|
||||
def test_raises_falsey_type_error(self) -> None:
|
||||
with pytest.raises(TypeError):
|
||||
with pytest.raises(AssertionError, match=0):
|
||||
with pytest.raises(AssertionError, match=0): # type: ignore[call-overload] # noqa: F821
|
||||
raise AssertionError("ohai")
|
||||
|
||||
def test_raises_repr_inflight(self):
|
||||
@@ -126,23 +126,23 @@ class TestRaises:
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*2 failed*"])
|
||||
|
||||
def test_noclass(self):
|
||||
def test_noclass(self) -> None:
|
||||
with pytest.raises(TypeError):
|
||||
pytest.raises("wrong", lambda: None)
|
||||
pytest.raises("wrong", lambda: None) # type: ignore[call-overload] # noqa: F821
|
||||
|
||||
def test_invalid_arguments_to_raises(self):
|
||||
def test_invalid_arguments_to_raises(self) -> None:
|
||||
with pytest.raises(TypeError, match="unknown"):
|
||||
with pytest.raises(TypeError, unknown="bogus"):
|
||||
with pytest.raises(TypeError, unknown="bogus"): # type: ignore[call-overload] # noqa: F821
|
||||
raise ValueError()
|
||||
|
||||
def test_tuple(self):
|
||||
with pytest.raises((KeyError, ValueError)):
|
||||
raise KeyError("oops")
|
||||
|
||||
def test_no_raise_message(self):
|
||||
def test_no_raise_message(self) -> None:
|
||||
try:
|
||||
pytest.raises(ValueError, int, "0")
|
||||
except pytest.raises.Exception as e:
|
||||
except pytest.fail.Exception as e:
|
||||
assert e.msg == "DID NOT RAISE {}".format(repr(ValueError))
|
||||
else:
|
||||
assert False, "Expected pytest.raises.Exception"
|
||||
@@ -150,7 +150,7 @@ class TestRaises:
|
||||
try:
|
||||
with pytest.raises(ValueError):
|
||||
pass
|
||||
except pytest.raises.Exception as e:
|
||||
except pytest.fail.Exception as e:
|
||||
assert e.msg == "DID NOT RAISE {}".format(repr(ValueError))
|
||||
else:
|
||||
assert False, "Expected pytest.raises.Exception"
|
||||
@@ -252,7 +252,7 @@ class TestRaises:
|
||||
):
|
||||
pytest.raises(ClassLooksIterableException, lambda: None)
|
||||
|
||||
def test_raises_with_raising_dunder_class(self):
|
||||
def test_raises_with_raising_dunder_class(self) -> None:
|
||||
"""Test current behavior with regard to exceptions via __class__ (#4284)."""
|
||||
|
||||
class CrappyClass(Exception):
|
||||
@@ -262,12 +262,12 @@ class TestRaises:
|
||||
assert False, "via __class__"
|
||||
|
||||
with pytest.raises(AssertionError) as excinfo:
|
||||
with pytest.raises(CrappyClass()):
|
||||
with pytest.raises(CrappyClass()): # type: ignore[call-overload] # noqa: F821
|
||||
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"):
|
||||
with pytest.raises(Exception, foo="bar"): # type: ignore[call-overload] # noqa: F821
|
||||
pass
|
||||
assert "Unexpected keyword arguments" in str(excinfo.value)
|
||||
|
||||
Reference in New Issue
Block a user