[pre-commit.ci] pre-commit autoupdate (#12115)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Ran Benita <ran@unusedvar.com>
This commit is contained in:
pre-commit-ci[bot]
2024-03-13 15:30:18 +02:00
committed by GitHub
parent 14437788f0
commit c0532dda18
61 changed files with 185 additions and 212 deletions

View File

@@ -16,8 +16,8 @@ import pytest
@contextlib.contextmanager
def ignore_encoding_warning():
with warnings.catch_warnings():
with contextlib.suppress(NameError): # new in 3.10
warnings.simplefilter("ignore", EncodingWarning) # type: ignore [name-defined]
if sys.version_info > (3, 10):
warnings.simplefilter("ignore", EncodingWarning)
yield
@@ -822,7 +822,7 @@ class TestLocalPath(CommonFSTests):
# depending on how the paths are used), but > 4096 (which is the
# Linux' limitation) - the behaviour of paths with names > 4096 chars
# is undetermined
newfilename = "/test" * 60 # type:ignore[unreachable]
newfilename = "/test" * 60 # type:ignore[unreachable,unused-ignore]
l1 = tmpdir.join(newfilename)
l1.ensure(file=True)
l1.write_text("foo", encoding="utf-8")
@@ -1368,8 +1368,8 @@ class TestPOSIXLocalPath:
assert realpath.basename == "file"
def test_owner(self, path1, tmpdir):
from grp import getgrgid # type:ignore[attr-defined]
from pwd import getpwuid # type:ignore[attr-defined]
from grp import getgrgid # type:ignore[attr-defined,unused-ignore]
from pwd import getpwuid # type:ignore[attr-defined,unused-ignore]
stat = path1.stat()
assert stat.path == path1

View File

@@ -180,7 +180,7 @@ class TestTraceback_f_g_h:
def test_traceback_cut_excludepath(self, pytester: Pytester) -> None:
p = pytester.makepyfile("def f(): raise ValueError")
with pytest.raises(ValueError) as excinfo:
import_path(p, root=pytester.path, consider_namespace_packages=False).f() # type: ignore[attr-defined]
import_path(p, root=pytester.path, consider_namespace_packages=False).f()
basedir = Path(pytest.__file__).parent
newtraceback = excinfo.traceback.cut(excludepath=basedir)
for x in newtraceback:

View File

@@ -1,5 +1,6 @@
# mypy: allow-untyped-defs
"""Reproduces issue #3774"""
from unittest import mock
import pytest

View File

@@ -1,5 +1,6 @@
# mypy: allow-untyped-defs
"""Skipping an entire subclass with unittest.skip() should *not* call setUp from a base class."""
import unittest

View File

@@ -1,5 +1,6 @@
# mypy: allow-untyped-defs
"""Skipping an entire subclass with unittest.skip() should *not* call setUpClass from a base class."""
import unittest

View File

@@ -1,5 +1,6 @@
# mypy: allow-untyped-defs
"""setUpModule is always called, even if all tests in the module are skipped"""
import unittest

View File

@@ -1,5 +1,6 @@
# mypy: allow-untyped-defs
"""Issue #7110"""
import asyncio
from typing import List

View File

@@ -11,8 +11,8 @@ import pytest
("a", 1),
("1", 1),
("א", 1),
("\u200B", 0),
("\u1ABE", 0),
("\u200b", 0),
("\u1abe", 0),
("\u0591", 0),
("🉐", 2),
("", 2), # noqa: RUF001

View File

@@ -109,7 +109,7 @@ class TestMetafunc:
metafunc = self.Metafunc(func)
# When the input is an iterator, only len(args) are taken,
# so the bad Exc isn't reached.
metafunc.parametrize("x", [1, 2], ids=gen()) # type: ignore[arg-type]
metafunc.parametrize("x", [1, 2], ids=gen())
assert [(x.params, x.id) for x in metafunc._calls] == [
({"x": 1}, "0"),
({"x": 2}, "2"),
@@ -121,7 +121,7 @@ class TestMetafunc:
r"Supported types are: .*"
),
):
metafunc.parametrize("x", [1, 2, 3], ids=gen()) # type: ignore[arg-type]
metafunc.parametrize("x", [1, 2, 3], ids=gen())
def test_parametrize_bad_scope(self) -> None:
def func(x):

View File

@@ -1243,7 +1243,7 @@ def test_disable_plugin_autoload(
monkeypatch.setenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "1")
monkeypatch.setattr(importlib.metadata, "distributions", distributions)
monkeypatch.setitem(sys.modules, "mytestplugin", PseudoPlugin()) # type: ignore[misc]
monkeypatch.setitem(sys.modules, "mytestplugin", PseudoPlugin())
config = pytester.parseconfig(*parse_args)
has_loaded = config.pluginmanager.get_plugin("mytestplugin") is not None
assert has_loaded == should_load

View File

@@ -29,7 +29,7 @@ def runpdb_and_get_stdout(pytester: Pytester, source: str):
def runpdb_and_get_report(pytester: Pytester, source: str):
result = runpdb(pytester, source)
reports = result.reprec.getreports("pytest_runtest_logreport") # type: ignore[attr-defined]
reports = result.reprec.getreports("pytest_runtest_logreport")
assert len(reports) == 3, reports # setup/call/teardown
return reports[1]

View File

@@ -1202,7 +1202,7 @@ def test_unicode_issue368(pytester: Pytester) -> None:
node_reporter.append_skipped(test_report)
test_report.longrepr = "filename", 1, "Skipped: 卡嘣嘣"
node_reporter.append_skipped(test_report)
test_report.wasxfail = ustr # type: ignore[attr-defined]
test_report.wasxfail = ustr
node_reporter.append_skipped(test_report)
log.pytest_sessionfinish()

View File

@@ -18,7 +18,7 @@ class TestMark:
@pytest.mark.parametrize("attr", ["mark", "param"])
def test_pytest_exists_in_namespace_all(self, attr: str) -> None:
module = sys.modules["pytest"]
assert attr in module.__all__ # type: ignore
assert attr in module.__all__
def test_pytest_mark_notcallable(self) -> None:
mark = MarkGenerator(_ispytest=True)
@@ -34,7 +34,7 @@ class TestMark:
assert pytest.mark.foo(some_function) is some_function
marked_with_args = pytest.mark.foo.with_args(some_function)
assert marked_with_args is not some_function # type: ignore[comparison-overlap]
assert marked_with_args is not some_function
assert pytest.mark.foo(SomeClass) is SomeClass
assert pytest.mark.foo.with_args(SomeClass) is not SomeClass # type: ignore[comparison-overlap]

View File

@@ -183,7 +183,7 @@ class TestImportPath:
obj = import_path(
path1 / "execfile.py", root=path1, consider_namespace_packages=ns_param
)
assert obj.x == 42 # type: ignore[attr-defined]
assert obj.x == 42
assert obj.__name__ == "execfile"
def test_import_path_missing_file(self, path1: Path, ns_param: bool) -> None:
@@ -246,7 +246,7 @@ class TestImportPath:
mod = import_path(
otherdir / "a.py", root=path1, consider_namespace_packages=ns_param
)
assert mod.result == "got it" # type: ignore[attr-defined]
assert mod.result == "got it"
assert mod.__name__ == "otherdir.a"
def test_b(self, path1: Path, ns_param: bool) -> None:
@@ -254,7 +254,7 @@ class TestImportPath:
mod = import_path(
otherdir / "b.py", root=path1, consider_namespace_packages=ns_param
)
assert mod.stuff == "got it" # type: ignore[attr-defined]
assert mod.stuff == "got it"
assert mod.__name__ == "otherdir.b"
def test_c(self, path1: Path, ns_param: bool) -> None:
@@ -262,14 +262,14 @@ class TestImportPath:
mod = import_path(
otherdir / "c.py", root=path1, consider_namespace_packages=ns_param
)
assert mod.value == "got it" # type: ignore[attr-defined]
assert mod.value == "got it"
def test_d(self, path1: Path, ns_param: bool) -> None:
otherdir = path1 / "otherdir"
mod = import_path(
otherdir / "d.py", root=path1, consider_namespace_packages=ns_param
)
assert mod.value2 == "got it" # type: ignore[attr-defined]
assert mod.value2 == "got it"
def test_import_after(self, tmp_path: Path, ns_param: bool) -> None:
tmp_path.joinpath("xxxpackage").mkdir()
@@ -360,7 +360,7 @@ class TestImportPath:
root=tmp_path,
consider_namespace_packages=ns_param,
)
assert module.foo(2) == 42 # type: ignore[attr-defined]
assert module.foo(2) == 42
assert str(simple_module.parent) not in sys.path
assert module.__name__ in sys.modules
assert module.__name__ == f"_src.tests.mymod_{request.node.name}"
@@ -400,7 +400,7 @@ class TestImportPath:
root=tmp_path,
consider_namespace_packages=ns_param,
)
assert module.foo(2) == 42 # type: ignore[attr-defined]
assert module.foo(2) == 42
# mode='importlib' fails if no spec is found to load the module
import importlib.util

View File

@@ -294,9 +294,9 @@ class TestReportSerialization:
reprec = pytester.inline_run()
if report_class is TestReport:
reports: Union[
Sequence[TestReport], Sequence[CollectReport]
] = reprec.getreports("pytest_runtest_logreport")
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

View File

@@ -1,5 +1,6 @@
# mypy: allow-untyped-defs
"""Test correct setup/teardowns at module, class, and instance level."""
from typing import List
from _pytest.pytester import Pytester

View File

@@ -1,5 +1,6 @@
# mypy: allow-untyped-defs
"""Terminal reporting of the full testing process."""
from io import StringIO
import os
from pathlib import Path

View File

@@ -4,6 +4,7 @@
This file is not executed, it is only checked by mypy to ensure that
none of the code triggers any mypy errors.
"""
import contextlib
from typing import Optional