py36+: com2ann
This commit is contained in:
@@ -778,7 +778,7 @@ raise ValueError()
|
||||
)
|
||||
excinfo = pytest.raises(ValueError, mod.entry)
|
||||
|
||||
styles = ("long", "short") # type: Tuple[_TracebackStyle, ...]
|
||||
styles: Tuple[_TracebackStyle, ...] = ("long", "short")
|
||||
for style in styles:
|
||||
p = FormattedExcinfo(style=style)
|
||||
reprtb = p.repr_traceback(excinfo)
|
||||
@@ -905,7 +905,7 @@ raise ValueError()
|
||||
)
|
||||
excinfo = pytest.raises(ValueError, mod.entry)
|
||||
|
||||
styles = ("short", "long", "no") # type: Tuple[_TracebackStyle, ...]
|
||||
styles: Tuple[_TracebackStyle, ...] = ("short", "long", "no")
|
||||
for style in styles:
|
||||
for showlocals in (True, False):
|
||||
repr = excinfo.getrepr(style=style, showlocals=showlocals)
|
||||
@@ -1370,7 +1370,7 @@ raise ValueError()
|
||||
@pytest.mark.parametrize("encoding", [None, "utf8", "utf16"])
|
||||
def test_repr_traceback_with_unicode(style, encoding):
|
||||
if encoding is None:
|
||||
msg = "☹" # type: Union[str, bytes]
|
||||
msg: Union[str, bytes] = "☹"
|
||||
else:
|
||||
msg = "☹".encode(encoding)
|
||||
try:
|
||||
|
||||
@@ -337,7 +337,7 @@ def test_findsource(monkeypatch) -> None:
|
||||
assert src is not None
|
||||
assert "if 1:" in str(src)
|
||||
|
||||
d = {} # type: Dict[str, Any]
|
||||
d: Dict[str, Any] = {}
|
||||
eval(co, d)
|
||||
src, lineno = findsource(d["x"])
|
||||
assert src is not None
|
||||
|
||||
@@ -15,7 +15,7 @@ def pytest_generate_tests(metafunc):
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def checked_order():
|
||||
order = [] # type: List[Tuple[str, str, str]]
|
||||
order: List[Tuple[str, str, str]] = []
|
||||
|
||||
yield order
|
||||
pprint.pprint(order)
|
||||
|
||||
@@ -2,7 +2,7 @@ from typing import List
|
||||
from unittest import IsolatedAsyncioTestCase # type: ignore
|
||||
|
||||
|
||||
teardowns = [] # type: List[None]
|
||||
teardowns: List[None] = []
|
||||
|
||||
|
||||
class AsyncArguments(IsolatedAsyncioTestCase):
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import List
|
||||
import asynctest
|
||||
|
||||
|
||||
teardowns = [] # type: List[None]
|
||||
teardowns: List[None] = []
|
||||
|
||||
|
||||
class Test(asynctest.TestCase):
|
||||
|
||||
@@ -41,7 +41,7 @@ def test_multiline_message() -> None:
|
||||
|
||||
logfmt = "%(filename)-25s %(lineno)4d %(levelname)-8s %(message)s"
|
||||
|
||||
record = logging.LogRecord(
|
||||
record: Any = logging.LogRecord(
|
||||
name="dummy",
|
||||
level=logging.INFO,
|
||||
pathname="dummypath",
|
||||
@@ -49,7 +49,7 @@ def test_multiline_message() -> None:
|
||||
msg="Test Message line1\nline2",
|
||||
args=(),
|
||||
exc_info=None,
|
||||
) # type: Any
|
||||
)
|
||||
# this is called by logging.Formatter.format
|
||||
record.message = record.getMessage()
|
||||
|
||||
|
||||
@@ -1040,7 +1040,7 @@ class TestTracebackCutting:
|
||||
from _pytest._code import filter_traceback
|
||||
|
||||
try:
|
||||
ns = {} # type: Dict[str, Any]
|
||||
ns: Dict[str, Any] = {}
|
||||
exec("def foo(): raise ValueError", ns)
|
||||
ns["foo"]()
|
||||
except ValueError:
|
||||
|
||||
@@ -33,7 +33,7 @@ class TestOEJSKITSpecials:
|
||||
# this hook finds funcarg factories
|
||||
rep = runner.collect_one_node(collector=modcol)
|
||||
# TODO: Don't treat as Any.
|
||||
clscol = rep.result[0] # type: Any
|
||||
clscol: Any = rep.result[0]
|
||||
clscol.obj = lambda arg1: None
|
||||
clscol.funcargs = {}
|
||||
pytest._fillfuncargs(clscol)
|
||||
@@ -67,7 +67,7 @@ class TestOEJSKITSpecials:
|
||||
# this hook finds funcarg factories
|
||||
rep = runner.collect_one_node(modcol)
|
||||
# TODO: Don't treat as Any.
|
||||
clscol = rep.result[0] # type: Any
|
||||
clscol: Any = rep.result[0]
|
||||
clscol.obj = lambda: None
|
||||
clscol.funcargs = {}
|
||||
pytest._fillfuncargs(clscol)
|
||||
|
||||
@@ -45,8 +45,8 @@ class TestMetafunc:
|
||||
_nodeid = attr.ib()
|
||||
|
||||
names = getfuncargnames(func)
|
||||
fixtureinfo = FuncFixtureInfoMock(names) # type: Any
|
||||
definition = DefinitionMock._create(func, "mock::nodeid") # type: Any
|
||||
fixtureinfo: Any = FuncFixtureInfoMock(names)
|
||||
definition: Any = DefinitionMock._create(func, "mock::nodeid")
|
||||
return python.Metafunc(definition, fixtureinfo, config)
|
||||
|
||||
def test_no_funcargs(self) -> None:
|
||||
@@ -326,10 +326,10 @@ class TestMetafunc:
|
||||
|
||||
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
|
||||
|
||||
values = [
|
||||
values: List[Tuple[str, Any, str]] = [
|
||||
("ação", MockConfig({option: True}), "ação"),
|
||||
("ação", MockConfig({option: False}), "a\\xe7\\xe3o"),
|
||||
] # type: List[Tuple[str, Any, str]]
|
||||
]
|
||||
for val, config, expected in values:
|
||||
actual = _idval(val, "a", 6, None, nodeid=None, config=config)
|
||||
assert actual == expected
|
||||
@@ -508,10 +508,10 @@ class TestMetafunc:
|
||||
|
||||
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
|
||||
|
||||
values = [
|
||||
values: List[Tuple[Any, str]] = [
|
||||
(MockConfig({option: True}), "ação"),
|
||||
(MockConfig({option: False}), "a\\xe7\\xe3o"),
|
||||
] # type: List[Tuple[Any, str]]
|
||||
]
|
||||
for config, expected in values:
|
||||
result = idmaker(
|
||||
("a",), [pytest.param("string")], idfn=lambda _: "ação", config=config,
|
||||
@@ -540,10 +540,10 @@ class TestMetafunc:
|
||||
|
||||
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
|
||||
|
||||
values = [
|
||||
values: List[Tuple[Any, str]] = [
|
||||
(MockConfig({option: True}), "ação"),
|
||||
(MockConfig({option: False}), "a\\xe7\\xe3o"),
|
||||
] # type: List[Tuple[Any, str]]
|
||||
]
|
||||
for config, expected in values:
|
||||
result = idmaker(
|
||||
("a",), [pytest.param("string")], ids=["ação"], config=config,
|
||||
@@ -1519,9 +1519,9 @@ class TestMetafuncFunctionalAuto:
|
||||
self, testdir: Testdir, monkeypatch
|
||||
) -> None:
|
||||
"""Integration test for (#3941)"""
|
||||
class_fix_setup = [] # type: List[object]
|
||||
class_fix_setup: List[object] = []
|
||||
monkeypatch.setattr(sys, "class_fix_setup", class_fix_setup, raising=False)
|
||||
func_fix_setup = [] # type: List[object]
|
||||
func_fix_setup: List[object] = []
|
||||
monkeypatch.setattr(sys, "func_fix_setup", func_fix_setup, raising=False)
|
||||
|
||||
testdir.makepyfile(
|
||||
|
||||
@@ -1068,7 +1068,7 @@ class TestTruncateExplanation:
|
||||
LINES_IN_TRUNCATION_MSG = 2
|
||||
|
||||
def test_doesnt_truncate_when_input_is_empty_list(self) -> None:
|
||||
expl = [] # type: List[str]
|
||||
expl: List[str] = []
|
||||
result = truncate._truncate_explanation(expl, max_lines=8, max_chars=100)
|
||||
assert result == expl
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ def getmsg(
|
||||
src = "\n".join(_pytest._code.Code(f).source().lines)
|
||||
mod = rewrite(src)
|
||||
code = compile(mod, "<test>", "exec")
|
||||
ns = {} # type: Dict[str, object]
|
||||
ns: Dict[str, object] = {}
|
||||
if extra_ns is not None:
|
||||
ns.update(extra_ns)
|
||||
exec(code, ns)
|
||||
@@ -1242,8 +1242,8 @@ class TestEarlyRewriteBailout:
|
||||
"""
|
||||
import importlib.machinery
|
||||
|
||||
self.find_spec_calls = [] # type: List[str]
|
||||
self.initial_paths = set() # type: Set[py.path.local]
|
||||
self.find_spec_calls: List[str] = []
|
||||
self.initial_paths: Set[py.path.local] = set()
|
||||
|
||||
class StubSession:
|
||||
_initialpaths = self.initial_paths
|
||||
|
||||
@@ -211,7 +211,7 @@ def test_cached_property() -> None:
|
||||
|
||||
|
||||
def test_assert_never_union() -> None:
|
||||
x = 10 # type: Union[int, str]
|
||||
x: Union[int, str] = 10
|
||||
|
||||
if isinstance(x, int):
|
||||
pass
|
||||
@@ -229,7 +229,7 @@ def test_assert_never_union() -> None:
|
||||
|
||||
def test_assert_never_enum() -> None:
|
||||
E = enum.Enum("E", "a b")
|
||||
x = E.a # type: E
|
||||
x: E = E.a
|
||||
|
||||
if x is E.a:
|
||||
pass
|
||||
@@ -246,7 +246,7 @@ def test_assert_never_enum() -> None:
|
||||
|
||||
|
||||
def test_assert_never_literal() -> None:
|
||||
x = "a" # type: Literal["a", "b"]
|
||||
x: Literal["a", "b"] = "a"
|
||||
|
||||
if x == "a":
|
||||
pass
|
||||
|
||||
@@ -507,7 +507,7 @@ class TestConfigCmdlineParsing:
|
||||
class TestConfigAPI:
|
||||
def test_config_trace(self, testdir) -> None:
|
||||
config = testdir.parseconfig()
|
||||
values = [] # type: List[str]
|
||||
values: List[str] = []
|
||||
config.trace.root.setwriter(values.append)
|
||||
config.trace("hello")
|
||||
assert len(values) == 1
|
||||
@@ -809,7 +809,7 @@ class TestConfigFromdictargs:
|
||||
|
||||
def test_invocation_params_args(self, _sys_snapshot) -> None:
|
||||
"""Show that fromdictargs can handle args in their "orig" format"""
|
||||
option_dict = {} # type: Dict[str, object]
|
||||
option_dict: Dict[str, object] = {}
|
||||
args = ["-vvvv", "-s", "a", "b"]
|
||||
|
||||
config = Config.fromdictargs(option_dict, args)
|
||||
|
||||
@@ -867,7 +867,7 @@ def test_mangle_test_address():
|
||||
|
||||
|
||||
def test_dont_configure_on_workers(tmpdir) -> None:
|
||||
gotten = [] # type: List[object]
|
||||
gotten: List[object] = []
|
||||
|
||||
class FakeConfig:
|
||||
if TYPE_CHECKING:
|
||||
@@ -1102,9 +1102,10 @@ def test_unicode_issue368(testdir) -> None:
|
||||
|
||||
class Report(BaseReport):
|
||||
longrepr = ustr
|
||||
sections = [] # type: List[Tuple[str, str]]
|
||||
sections: List[Tuple[str, str]] = []
|
||||
nodeid = "something"
|
||||
location = "tests/filename.py", 42, "TestClass.method"
|
||||
when = "teardown"
|
||||
|
||||
test_report = cast(TestReport, Report())
|
||||
|
||||
@@ -1372,7 +1373,7 @@ def test_global_properties(testdir, xunit_family) -> None:
|
||||
log = LogXML(str(path), None, family=xunit_family)
|
||||
|
||||
class Report(BaseReport):
|
||||
sections = [] # type: List[Tuple[str, str]]
|
||||
sections: List[Tuple[str, str]] = []
|
||||
nodeid = "test_node_id"
|
||||
|
||||
log.pytest_sessionstart()
|
||||
@@ -1408,7 +1409,7 @@ def test_url_property(testdir) -> None:
|
||||
|
||||
class Report(BaseReport):
|
||||
longrepr = "FooBarBaz"
|
||||
sections = [] # type: List[Tuple[str, str]]
|
||||
sections: List[Tuple[str, str]] = []
|
||||
nodeid = "something"
|
||||
location = "tests/filename.py", 42, "TestClass.method"
|
||||
url = test_url
|
||||
|
||||
@@ -13,7 +13,7 @@ import pytest
|
||||
|
||||
|
||||
def _modules() -> List[str]:
|
||||
pytest_pkg = _pytest.__path__ # type: str # type: ignore
|
||||
pytest_pkg: str = _pytest.__path__ # type: ignore
|
||||
return sorted(
|
||||
n
|
||||
for _, n, _ in pkgutil.walk_packages(pytest_pkg, prefix=_pytest.__name__ + ".")
|
||||
|
||||
@@ -130,7 +130,7 @@ def test_setitem() -> None:
|
||||
|
||||
|
||||
def test_setitem_deleted_meanwhile() -> None:
|
||||
d = {} # type: Dict[str, object]
|
||||
d: Dict[str, object] = {}
|
||||
monkeypatch = MonkeyPatch()
|
||||
monkeypatch.setitem(d, "x", 2)
|
||||
del d["x"]
|
||||
@@ -155,7 +155,7 @@ def test_setenv_deleted_meanwhile(before: bool) -> None:
|
||||
|
||||
|
||||
def test_delitem() -> None:
|
||||
d = {"x": 1} # type: Dict[str, object]
|
||||
d: Dict[str, object] = {"x": 1}
|
||||
monkeypatch = MonkeyPatch()
|
||||
monkeypatch.delitem(d, "x")
|
||||
assert "x" not in d
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
class TestPasteCapture:
|
||||
@pytest.fixture
|
||||
def pastebinlist(self, monkeypatch, request) -> List[Union[str, bytes]]:
|
||||
pastebinlist = [] # type: List[Union[str, bytes]]
|
||||
pastebinlist: List[Union[str, bytes]] = []
|
||||
plugin = request.config.pluginmanager.getplugin("pastebin")
|
||||
monkeypatch.setattr(plugin, "create_new_paste", pastebinlist.append)
|
||||
return pastebinlist
|
||||
|
||||
@@ -100,7 +100,7 @@ class TestPytestPluginInteractions:
|
||||
saveindent.append(pytestpm.trace.root.indent)
|
||||
raise ValueError()
|
||||
|
||||
values = [] # type: List[str]
|
||||
values: List[str] = []
|
||||
pytestpm.trace.root.setwriter(values.append)
|
||||
undo = pytestpm.enable_tracing()
|
||||
try:
|
||||
|
||||
@@ -227,7 +227,7 @@ class TestInlineRunModulesCleanup:
|
||||
|
||||
def spy_factory(self):
|
||||
class SysModulesSnapshotSpy:
|
||||
instances = [] # type: List[SysModulesSnapshotSpy]
|
||||
instances: List["SysModulesSnapshotSpy"] = [] # noqa: F821
|
||||
|
||||
def __init__(self, preserve=None) -> None:
|
||||
SysModulesSnapshotSpy.instances.append(self)
|
||||
@@ -408,7 +408,7 @@ class TestSysPathsSnapshot:
|
||||
original_data = list(getattr(sys, path_type))
|
||||
original_other = getattr(sys, other_path_type)
|
||||
original_other_data = list(original_other)
|
||||
new = [] # type: List[object]
|
||||
new: List[object] = []
|
||||
snapshot = SysPathsSnapshot()
|
||||
monkeypatch.setattr(sys, path_type, new)
|
||||
snapshot.restore()
|
||||
|
||||
@@ -286,9 +286,9 @@ class TestReportSerialization:
|
||||
|
||||
reprec = testdir.inline_run()
|
||||
if report_class is TestReport:
|
||||
reports = reprec.getreports(
|
||||
"pytest_runtest_logreport"
|
||||
) # type: Union[Sequence[TestReport], Sequence[CollectReport]]
|
||||
reports: Union[
|
||||
Sequence[TestReport], Sequence[CollectReport]
|
||||
] = reprec.getreports("pytest_runtest_logreport")
|
||||
# we have 3 reports: setup/call/teardown
|
||||
assert len(reports) == 3
|
||||
# get the call report
|
||||
|
||||
@@ -444,11 +444,11 @@ class TestSessionReports:
|
||||
assert res[1].name == "TestClass"
|
||||
|
||||
|
||||
reporttypes = [
|
||||
reporttypes: List[Type[reports.BaseReport]] = [
|
||||
reports.BaseReport,
|
||||
reports.TestReport,
|
||||
reports.CollectReport,
|
||||
] # type: List[Type[reports.BaseReport]]
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -456,7 +456,7 @@ reporttypes = [
|
||||
)
|
||||
def test_report_extra_parameters(reporttype: Type[reports.BaseReport]) -> None:
|
||||
args = list(inspect.signature(reporttype.__init__).parameters.keys())[1:]
|
||||
basekw = dict.fromkeys(args, []) # type: Dict[str, List[object]]
|
||||
basekw: Dict[str, List[object]] = dict.fromkeys(args, [])
|
||||
report = reporttype(newthing=1, **basekw)
|
||||
assert report.newthing == 1
|
||||
|
||||
@@ -898,7 +898,7 @@ def test_store_except_info_on_error() -> None:
|
||||
|
||||
|
||||
def test_current_test_env_var(testdir, monkeypatch) -> None:
|
||||
pytest_current_test_vars = [] # type: List[Tuple[str, str]]
|
||||
pytest_current_test_vars: List[Tuple[str, str]] = []
|
||||
monkeypatch.setattr(
|
||||
sys, "pytest_current_test_vars", pytest_current_test_vars, raising=False
|
||||
)
|
||||
|
||||
@@ -246,7 +246,7 @@ def test_setup_teardown_function_level_with_optional_argument(
|
||||
"""Parameter to setup/teardown xunit-style functions parameter is now optional (#1728)."""
|
||||
import sys
|
||||
|
||||
trace_setups_teardowns = [] # type: List[str]
|
||||
trace_setups_teardowns: List[str] = []
|
||||
monkeypatch.setattr(
|
||||
sys, "trace_setups_teardowns", trace_setups_teardowns, raising=False
|
||||
)
|
||||
|
||||
@@ -270,7 +270,7 @@ class TestNumberedDir:
|
||||
def test_lock_register_cleanup_removal(self, tmp_path: Path) -> None:
|
||||
lock = create_cleanup_lock(tmp_path)
|
||||
|
||||
registry = [] # type: List[Callable[..., None]]
|
||||
registry: List[Callable[..., None]] = []
|
||||
register_cleanup_lock_removal(lock, register=registry.append)
|
||||
|
||||
(cleanup_func,) = registry
|
||||
|
||||
@@ -1162,7 +1162,7 @@ def test_pdb_teardown_called(testdir, monkeypatch) -> None:
|
||||
We delay the normal tearDown() calls when --pdb is given, so this ensures we are calling
|
||||
tearDown() eventually to avoid memory leaks when using --pdb.
|
||||
"""
|
||||
teardowns = [] # type: List[str]
|
||||
teardowns: List[str] = []
|
||||
monkeypatch.setattr(
|
||||
pytest, "test_pdb_teardown_called_teardowns", teardowns, raising=False
|
||||
)
|
||||
@@ -1194,7 +1194,7 @@ def test_pdb_teardown_called(testdir, monkeypatch) -> None:
|
||||
@pytest.mark.parametrize("mark", ["@unittest.skip", "@pytest.mark.skip"])
|
||||
def test_pdb_teardown_skipped(testdir, monkeypatch, mark: str) -> None:
|
||||
"""With --pdb, setUp and tearDown should not be called for skipped tests."""
|
||||
tracked = [] # type: List[str]
|
||||
tracked: List[str] = []
|
||||
monkeypatch.setattr(pytest, "test_pdb_teardown_skipped", tracked, raising=False)
|
||||
|
||||
testdir.makepyfile(
|
||||
|
||||
@@ -656,9 +656,9 @@ class TestStackLevel:
|
||||
@pytest.fixture
|
||||
def capwarn(self, testdir):
|
||||
class CapturedWarnings:
|
||||
captured = (
|
||||
[]
|
||||
) # type: List[Tuple[warnings.WarningMessage, Optional[Tuple[str, int, str]]]]
|
||||
captured: List[
|
||||
Tuple[warnings.WarningMessage, Optional[Tuple[str, int, str]]]
|
||||
] = ([])
|
||||
|
||||
@classmethod
|
||||
def pytest_warning_recorded(cls, warning_message, when, nodeid, location):
|
||||
|
||||
Reference in New Issue
Block a user