From b41bdc50be6bcb6a2bf1d21b599fc85fa40b5bd3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:40:31 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/generate-gh-release-notes.py | 1 + scripts/prepare-release-pr.py | 1 + scripts/release.py | 1 + src/_pytest/_code/code.py | 26 +++++++++---------- src/_pytest/_code/source.py | 6 ++--- src/_pytest/_py/path.py | 13 ++++------ src/_pytest/assertion/__init__.py | 1 + src/_pytest/assertion/rewrite.py | 6 ++--- src/_pytest/assertion/util.py | 5 ++-- src/_pytest/cacheprovider.py | 1 + src/_pytest/capture.py | 21 +++------------ src/_pytest/compat.py | 2 +- src/_pytest/config/__init__.py | 1 + src/_pytest/debugging.py | 1 + src/_pytest/doctest.py | 1 + src/_pytest/fixtures.py | 22 +++++----------- src/_pytest/helpconfig.py | 1 + src/_pytest/hookspec.py | 1 + src/_pytest/junitxml.py | 3 ++- src/_pytest/logging.py | 1 + src/_pytest/main.py | 6 ++--- src/_pytest/mark/structures.py | 18 +++++-------- src/_pytest/monkeypatch.py | 7 +++-- src/_pytest/nodes.py | 6 ++--- src/_pytest/pastebin.py | 1 + src/_pytest/pytester.py | 22 ++++++---------- src/_pytest/python.py | 1 + src/_pytest/python_api.py | 6 ++--- src/_pytest/recwarn.py | 13 ++++------ src/_pytest/reports.py | 9 +++---- src/_pytest/runner.py | 1 + src/_pytest/skipping.py | 1 + src/_pytest/terminal.py | 1 + src/_pytest/tmpdir.py | 1 + src/_pytest/unittest.py | 1 + src/pytest/__init__.py | 1 + .../acceptance/fixture_mock_integration.py | 1 + .../unittest/test_setup_skip.py | 1 + .../unittest/test_setup_skip_class.py | 1 + .../unittest/test_setup_skip_module.py | 1 + .../unittest/test_unittest_asynctest.py | 1 + testing/io/test_wcwidth.py | 4 +-- testing/test_reports.py | 6 ++--- testing/test_runner_xunit.py | 1 + testing/test_terminal.py | 1 + testing/typing_checks.py | 1 + 46 files changed, 102 insertions(+), 126 deletions(-) diff --git a/scripts/generate-gh-release-notes.py b/scripts/generate-gh-release-notes.py index c27f5774b..4222702d5 100644 --- a/scripts/generate-gh-release-notes.py +++ b/scripts/generate-gh-release-notes.py @@ -8,6 +8,7 @@ our CHANGELOG) into Markdown (which is required by GitHub Releases). Requires Python3.6+. """ + from pathlib import Path import re import sys diff --git a/scripts/prepare-release-pr.py b/scripts/prepare-release-pr.py index 8a9f0aa0f..7dabbd3b3 100644 --- a/scripts/prepare-release-pr.py +++ b/scripts/prepare-release-pr.py @@ -13,6 +13,7 @@ After that, it will create a release using the `release` tox environment, and pu **Token**: currently the token from the GitHub Actions is used, pushed with `pytest bot ` commit author. """ + import argparse from pathlib import Path import re diff --git a/scripts/release.py b/scripts/release.py index 73f5f52b1..bcbc4262d 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -1,5 +1,6 @@ # mypy: disallow-untyped-defs """Invoke development tasks.""" + import argparse import os from pathlib import Path diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 12168be60..b7d8182ee 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -279,9 +279,9 @@ class TracebackEntry: Mostly for internal use. """ - tbh: Union[ - bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool] - ] = False + tbh: Union[bool, Callable[[Optional[ExceptionInfo[BaseException]]], bool]] = ( + False + ) for maybe_ns_dct in (self.frame.f_locals, self.frame.f_globals): # in normal cases, f_locals and f_globals are dictionaries # however via `exec(...)` / `eval(...)` they can be other types @@ -378,12 +378,10 @@ class Traceback(List[TracebackEntry]): return self @overload - def __getitem__(self, key: "SupportsIndex") -> TracebackEntry: - ... + def __getitem__(self, key: "SupportsIndex") -> TracebackEntry: ... @overload - def __getitem__(self, key: slice) -> "Traceback": - ... + def __getitem__(self, key: slice) -> "Traceback": ... def __getitem__( self, key: Union["SupportsIndex", slice] @@ -1051,13 +1049,13 @@ class FormattedExcinfo: # full support for exception groups added to ExceptionInfo. # See https://github.com/pytest-dev/pytest/issues/9159 if isinstance(e, BaseExceptionGroup): - reprtraceback: Union[ - ReprTracebackNative, ReprTraceback - ] = ReprTracebackNative( - traceback.format_exception( - type(excinfo_.value), - excinfo_.value, - excinfo_.traceback[0]._rawentry, + reprtraceback: Union[ReprTracebackNative, ReprTraceback] = ( + ReprTracebackNative( + traceback.format_exception( + type(excinfo_.value), + excinfo_.value, + excinfo_.traceback[0]._rawentry, + ) ) ) else: diff --git a/src/_pytest/_code/source.py b/src/_pytest/_code/source.py index dac3c3867..7fa577e03 100644 --- a/src/_pytest/_code/source.py +++ b/src/_pytest/_code/source.py @@ -47,12 +47,10 @@ class Source: __hash__ = None # type: ignore @overload - def __getitem__(self, key: int) -> str: - ... + def __getitem__(self, key: int) -> str: ... @overload - def __getitem__(self, key: slice) -> "Source": - ... + def __getitem__(self, key: slice) -> "Source": ... def __getitem__(self, key: Union[int, slice]) -> Union[str, "Source"]: if isinstance(key, int): diff --git a/src/_pytest/_py/path.py b/src/_pytest/_py/path.py index 7701561d9..75c7e1a50 100644 --- a/src/_pytest/_py/path.py +++ b/src/_pytest/_py/path.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """local path implementation.""" + from __future__ import annotations import atexit @@ -205,12 +206,10 @@ class Stat: if TYPE_CHECKING: @property - def size(self) -> int: - ... + def size(self) -> int: ... @property - def mtime(self) -> float: - ... + def mtime(self) -> float: ... def __getattr__(self, name: str) -> Any: return getattr(self._osstatresult, "st_" + name) @@ -966,12 +965,10 @@ class LocalPath: return p @overload - def stat(self, raising: Literal[True] = ...) -> Stat: - ... + def stat(self, raising: Literal[True] = ...) -> Stat: ... @overload - def stat(self, raising: Literal[False]) -> Stat | None: - ... + def stat(self, raising: Literal[False]) -> Stat | None: ... def stat(self, raising: bool = True) -> Stat | None: """Return an os.stat() tuple.""" diff --git a/src/_pytest/assertion/__init__.py b/src/_pytest/assertion/__init__.py index ea71230e1..21dd4a4a4 100644 --- a/src/_pytest/assertion/__init__.py +++ b/src/_pytest/assertion/__init__.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Support for presenting detailed information in failing assertions.""" + import sys from typing import Any from typing import Generator diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index ddae34c73..2777c9ce9 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -672,9 +672,9 @@ class AssertionRewriter(ast.NodeVisitor): self.enable_assertion_pass_hook = False self.source = source self.scope: tuple[ast.AST, ...] = () - self.variables_overwrite: defaultdict[ - tuple[ast.AST, ...], Dict[str, str] - ] = defaultdict(dict) + self.variables_overwrite: defaultdict[tuple[ast.AST, ...], Dict[str, str]] = ( + defaultdict(dict) + ) def run(self, mod: ast.Module) -> None: """Find all assert statements in *mod* and rewrite them.""" diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index ca3df7490..d0771b611 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Utilities for assertion debugging.""" + import collections.abc import os import pprint @@ -223,9 +224,7 @@ def assertrepr_compare( raise except Exception: explanation = [ - "(pytest_assertion plugin: representation of details failed: {}.".format( - _pytest._code.ExceptionInfo.from_current()._getreprcrash() - ), + f"(pytest_assertion plugin: representation of details failed: {_pytest._code.ExceptionInfo.from_current()._getreprcrash()}.", " Probably an object has a faulty __repr__.)", ] diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 5ccd2168d..7e97ab45f 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Implementation of the cache provider.""" + # This plugin was not named "cache" to avoid conflicts with the external # pytest-cache version. import dataclasses diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index dce431c3d..e544543ed 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Per-test stdout/stderr capturing mechanism.""" + import abc import collections import contextlib @@ -482,13 +483,7 @@ class FDCaptureBase(CaptureBase[AnyStr]): self._state = "initialized" def __repr__(self) -> str: - return "<{} {} oldfd={} _state={!r} tmpfile={!r}>".format( - self.__class__.__name__, - self.targetfd, - self.targetfd_save, - self._state, - self.tmpfile, - ) + return f"<{self.__class__.__name__} {self.targetfd} oldfd={self.targetfd_save} _state={self._state!r} tmpfile={self.tmpfile!r}>" def _assert_state(self, op: str, states: Tuple[str, ...]) -> None: assert ( @@ -621,13 +616,7 @@ class MultiCapture(Generic[AnyStr]): self.err: Optional[CaptureBase[AnyStr]] = err def __repr__(self) -> str: - return "".format( - self.out, - self.err, - self.in_, - self._state, - self._in_suspended, - ) + return f"" def start_capturing(self) -> None: self._state = "started" @@ -735,9 +724,7 @@ class CaptureManager: self._capture_fixture: Optional[CaptureFixture[Any]] = None def __repr__(self) -> str: - return "".format( - self._method, self._global_capturing, self._capture_fixture - ) + return f"" def is_capturing(self) -> Union[str, bool]: if self.is_globally_capturing(): diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 8d49d6fb6..9d9411818 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -304,7 +304,7 @@ def get_user_id() -> int | None: # mypy follows the version and platform checking expectation of PEP 484: # https://mypy.readthedocs.io/en/stable/common_issues.html?highlight=platform#python-version-and-system-platform-checks # Containment checks are too complex for mypy v1.5.0 and cause failure. - if sys.platform == "win32" or sys.platform == "emscripten": # noqa: PLR1714 + if sys.platform == "win32" or sys.platform == "emscripten": # win32 does not have a getuid() function. # Emscripten has a return 0 stub. return None diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index bf2cfc399..7ff27643f 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Command line options, ini-file and conftest.py processing.""" + import argparse import collections.abc import copy diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index cb157cd67..bf0f2ef8d 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Interactive debugging with PDB, the Python Debugger.""" + import argparse import functools import sys diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index ced3b82f5..7fff99f37 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Discover and run doctests in modules and test files.""" + import bdb from contextlib import contextmanager import functools diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index daf3145aa..b14109995 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -631,15 +631,9 @@ class FixtureRequest(abc.ABC): source_path_str = str(source_path) msg = ( "The requested fixture has no parameter defined for test:\n" - " {}\n\n" - "Requested fixture '{}' defined in:\n{}" - "\n\nRequested here:\n{}:{}".format( - funcitem.nodeid, - fixturedef.argname, - getlocation(fixturedef.func, funcitem.config.rootpath), - source_path_str, - source_lineno, - ) + f" {funcitem.nodeid}\n\n" + f"Requested fixture '{fixturedef.argname}' defined in:\n{getlocation(fixturedef.func, funcitem.config.rootpath)}" + f"\n\nRequested here:\n{source_path_str}:{source_lineno}" ) fail(msg, pytrace=False) @@ -1148,11 +1142,11 @@ def wrap_function_to_error_out_if_called_directly( """Wrap the given fixture function so we can raise an error about it being called directly, instead of used as an argument in a test function.""" message = ( - 'Fixture "{name}" called directly. Fixtures are not meant to be called directly,\n' + f'Fixture "{fixture_marker.name or function.__name__}" called directly. Fixtures are not meant to be called directly,\n' "but are created automatically when test functions request them as parameters.\n" "See https://docs.pytest.org/en/stable/explanation/fixtures.html for more information about fixtures, and\n" "https://docs.pytest.org/en/stable/deprecations.html#calling-fixtures-directly about how to update your code." - ).format(name=fixture_marker.name or function.__name__) + ) @functools.wraps(function) def result(*args, **kwargs): @@ -1219,8 +1213,7 @@ def fixture( Union[Sequence[Optional[object]], Callable[[Any], Optional[object]]] ] = ..., name: Optional[str] = ..., -) -> FixtureFunction: - ... +) -> FixtureFunction: ... @overload @@ -1234,8 +1227,7 @@ def fixture( Union[Sequence[Optional[object]], Callable[[Any], Optional[object]]] ] = ..., name: Optional[str] = None, -) -> FixtureFunctionMarker: - ... +) -> FixtureFunctionMarker: ... def fixture( diff --git a/src/_pytest/helpconfig.py b/src/_pytest/helpconfig.py index aa8bf65c7..37fbdf04d 100644 --- a/src/_pytest/helpconfig.py +++ b/src/_pytest/helpconfig.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Version info, help messages, tracing configuration.""" + from argparse import Action import os import sys diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 4bee76f1e..db55bd82d 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -1,6 +1,7 @@ # mypy: allow-untyped-defs """Hook specifications for pytest plugins which are invoked by pytest itself and by builtin plugins.""" + from pathlib import Path from typing import Any from typing import Dict diff --git a/src/_pytest/junitxml.py b/src/_pytest/junitxml.py index 4ca356f31..492df77f3 100644 --- a/src/_pytest/junitxml.py +++ b/src/_pytest/junitxml.py @@ -7,6 +7,7 @@ Based on initial code from Ross Lawley. Output conforms to https://github.com/jenkinsci/xunit-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd """ + from datetime import datetime import functools import os @@ -60,7 +61,7 @@ def bin_xml_escape(arg: object) -> str: # Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] # For an unknown(?) reason, we disallow #x7F (DEL) as well. illegal_xml_re = ( - "[^\u0009\u000A\u000D\u0020-\u007E\u0080-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]" + "[^\u0009\u000a\u000d\u0020-\u007e\u0080-\ud7ff\ue000-\ufffd\u10000-\u10ffFF]" ) return re.sub(illegal_xml_re, repl, str(arg)) diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py index e9a3234fd..2890d5a11 100644 --- a/src/_pytest/logging.py +++ b/src/_pytest/logging.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Access and control log capturing.""" + from contextlib import contextmanager from contextlib import nullcontext from datetime import datetime diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 3b9ac93cf..716d5cf78 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -736,14 +736,12 @@ class Session(nodes.Collector): @overload def perform_collect( self, args: Optional[Sequence[str]] = ..., genitems: "Literal[True]" = ... - ) -> Sequence[nodes.Item]: - ... + ) -> Sequence[nodes.Item]: ... @overload def perform_collect( self, args: Optional[Sequence[str]] = ..., genitems: bool = ... - ) -> Sequence[Union[nodes.Item, nodes.Collector]]: - ... + ) -> Sequence[Union[nodes.Item, nodes.Collector]]: ... def perform_collect( self, args: Optional[Sequence[str]] = None, genitems: bool = True diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 1da300c82..6072be167 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -434,12 +434,10 @@ if TYPE_CHECKING: class _SkipMarkDecorator(MarkDecorator): @overload # type: ignore[override,misc,no-overload-impl] - def __call__(self, arg: Markable) -> Markable: - ... + def __call__(self, arg: Markable) -> Markable: ... @overload - def __call__(self, reason: str = ...) -> "MarkDecorator": - ... + def __call__(self, reason: str = ...) -> "MarkDecorator": ... class _SkipifMarkDecorator(MarkDecorator): def __call__( # type: ignore[override] @@ -447,13 +445,11 @@ if TYPE_CHECKING: condition: Union[str, bool] = ..., *conditions: Union[str, bool], reason: str = ..., - ) -> MarkDecorator: - ... + ) -> MarkDecorator: ... class _XfailMarkDecorator(MarkDecorator): @overload # type: ignore[override,misc,no-overload-impl] - def __call__(self, arg: Markable) -> Markable: - ... + def __call__(self, arg: Markable) -> Markable: ... @overload def __call__( @@ -466,8 +462,7 @@ if TYPE_CHECKING: None, Type[BaseException], Tuple[Type[BaseException], ...] ] = ..., strict: bool = ..., - ) -> MarkDecorator: - ... + ) -> MarkDecorator: ... class _ParametrizeMarkDecorator(MarkDecorator): def __call__( # type: ignore[override] @@ -483,8 +478,7 @@ if TYPE_CHECKING: ] ] = ..., scope: Optional[_ScopeName] = ..., - ) -> MarkDecorator: - ... + ) -> MarkDecorator: ... class _UsefixturesMarkDecorator(MarkDecorator): def __call__(self, *fixtures: str) -> MarkDecorator: # type: ignore[override] diff --git a/src/_pytest/monkeypatch.py b/src/_pytest/monkeypatch.py index e96a93868..3f398df76 100644 --- a/src/_pytest/monkeypatch.py +++ b/src/_pytest/monkeypatch.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Monkeypatching and mocking functionality.""" + from contextlib import contextmanager import os import re @@ -167,8 +168,7 @@ class MonkeyPatch: name: object, value: Notset = ..., raising: bool = ..., - ) -> None: - ... + ) -> None: ... @overload def setattr( @@ -177,8 +177,7 @@ class MonkeyPatch: name: str, value: object, raising: bool = ..., - ) -> None: - ... + ) -> None: ... def setattr( self, diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index cff15001c..1b91bdb6e 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -363,12 +363,10 @@ class Node(abc.ABC, metaclass=NodeMeta): yield node, mark @overload - def get_closest_marker(self, name: str) -> Optional[Mark]: - ... + def get_closest_marker(self, name: str) -> Optional[Mark]: ... @overload - def get_closest_marker(self, name: str, default: Mark) -> Mark: - ... + def get_closest_marker(self, name: str, default: Mark) -> Mark: ... def get_closest_marker( self, name: str, default: Optional[Mark] = None diff --git a/src/_pytest/pastebin.py b/src/_pytest/pastebin.py index 98ba5c9c1..533d78c9a 100644 --- a/src/_pytest/pastebin.py +++ b/src/_pytest/pastebin.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Submit failure or test session information to a pastebin service.""" + from io import StringIO import tempfile from typing import IO diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 8002528b9..23f44da69 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -3,6 +3,7 @@ PYTEST_DONT_REWRITE """ + import collections.abc import contextlib from fnmatch import fnmatch @@ -245,8 +246,7 @@ class RecordedHookCall: if TYPE_CHECKING: # The class has undetermined attributes, this tells mypy about it. - def __getattr__(self, key: str): - ... + def __getattr__(self, key: str): ... @final @@ -327,15 +327,13 @@ class HookRecorder: def getreports( self, names: "Literal['pytest_collectreport']", - ) -> Sequence[CollectReport]: - ... + ) -> Sequence[CollectReport]: ... @overload def getreports( self, names: "Literal['pytest_runtest_logreport']", - ) -> Sequence[TestReport]: - ... + ) -> Sequence[TestReport]: ... @overload def getreports( @@ -344,8 +342,7 @@ class HookRecorder: "pytest_collectreport", "pytest_runtest_logreport", ), - ) -> Sequence[Union[CollectReport, TestReport]]: - ... + ) -> Sequence[Union[CollectReport, TestReport]]: ... def getreports( self, @@ -390,15 +387,13 @@ class HookRecorder: def getfailures( self, names: "Literal['pytest_collectreport']", - ) -> Sequence[CollectReport]: - ... + ) -> Sequence[CollectReport]: ... @overload def getfailures( self, names: "Literal['pytest_runtest_logreport']", - ) -> Sequence[TestReport]: - ... + ) -> Sequence[TestReport]: ... @overload def getfailures( @@ -407,8 +402,7 @@ class HookRecorder: "pytest_collectreport", "pytest_runtest_logreport", ), - ) -> Sequence[Union[CollectReport, TestReport]]: - ... + ) -> Sequence[Union[CollectReport, TestReport]]: ... def getfailures( self, diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 7b0683b6e..3242d517e 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Python test discovery, setup and run of test functions.""" + import abc from collections import Counter from collections import defaultdict diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 7e51da319..dc7c20cf4 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -769,8 +769,7 @@ def raises( expected_exception: Union[Type[E], Tuple[Type[E], ...]], *, match: Optional[Union[str, Pattern[str]]] = ..., -) -> "RaisesContext[E]": - ... +) -> "RaisesContext[E]": ... @overload @@ -779,8 +778,7 @@ def raises( func: Callable[..., Any], *args: Any, **kwargs: Any, -) -> _pytest._code.ExceptionInfo[E]: - ... +) -> _pytest._code.ExceptionInfo[E]: ... def raises( diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index bcf9f1466..c6d95f4b8 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Record warnings during test function execution.""" + from pprint import pformat import re from types import TracebackType @@ -43,13 +44,11 @@ def recwarn() -> Generator["WarningsRecorder", None, None]: @overload def deprecated_call( *, match: Optional[Union[str, Pattern[str]]] = ... -) -> "WarningsRecorder": - ... +) -> "WarningsRecorder": ... @overload -def deprecated_call(func: Callable[..., T], *args: Any, **kwargs: Any) -> T: - ... +def deprecated_call(func: Callable[..., T], *args: Any, **kwargs: Any) -> T: ... def deprecated_call( @@ -91,8 +90,7 @@ def warns( expected_warning: Union[Type[Warning], Tuple[Type[Warning], ...]] = ..., *, match: Optional[Union[str, Pattern[str]]] = ..., -) -> "WarningsChecker": - ... +) -> "WarningsChecker": ... @overload @@ -101,8 +99,7 @@ def warns( func: Callable[..., T], *args: Any, **kwargs: Any, -) -> T: - ... +) -> T: ... def warns( diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index 7cdb70e32..70f3212ce 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -72,8 +72,7 @@ class BaseReport: if TYPE_CHECKING: # Can have arbitrary fields given to __init__(). - def __getattr__(self, key: str) -> Any: - ... + def __getattr__(self, key: str) -> Any: ... def toterminal(self, out: TerminalWriter) -> None: if hasattr(self, "node"): @@ -606,9 +605,9 @@ def _report_kwargs_from_json(reportdict: Dict[str, Any]) -> Dict[str, Any]: description, ) ) - exception_info: Union[ - ExceptionChainRepr, ReprExceptionInfo - ] = ExceptionChainRepr(chain) + exception_info: Union[ExceptionChainRepr, ReprExceptionInfo] = ( + ExceptionChainRepr(chain) + ) else: exception_info = ReprExceptionInfo( reprtraceback=reprtraceback, diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 16abb895d..f60b446b8 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Basic collect and runtest protocol implementations.""" + import bdb import dataclasses import os diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index 4799ae649..74ddc193a 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Support for skip/xfail functions and markers.""" + from collections.abc import Mapping import dataclasses import os diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 75d57197a..2c9c0d3b1 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -3,6 +3,7 @@ This is a good source for looking at the various reporting hooks. """ + import argparse from collections import Counter import dataclasses diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 1cb9fbbe0..72efed3e8 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Support for providing temporary directories to test functions.""" + import dataclasses import os from pathlib import Path diff --git a/src/_pytest/unittest.py b/src/_pytest/unittest.py index 32eb361c6..17a8d3f03 100644 --- a/src/_pytest/unittest.py +++ b/src/_pytest/unittest.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Discover and run std-library "unittest" style tests.""" + import sys import traceback import types diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py index 20829aa58..c6b6de827 100644 --- a/src/pytest/__init__.py +++ b/src/pytest/__init__.py @@ -1,5 +1,6 @@ # PYTHON_ARGCOMPLETE_OK """pytest: unit and functional testing with Python.""" + from _pytest import __version__ from _pytest import version_tuple from _pytest._code import ExceptionInfo diff --git a/testing/example_scripts/acceptance/fixture_mock_integration.py b/testing/example_scripts/acceptance/fixture_mock_integration.py index 36e711f40..d802a7f87 100644 --- a/testing/example_scripts/acceptance/fixture_mock_integration.py +++ b/testing/example_scripts/acceptance/fixture_mock_integration.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Reproduces issue #3774""" + from unittest import mock import pytest diff --git a/testing/example_scripts/unittest/test_setup_skip.py b/testing/example_scripts/unittest/test_setup_skip.py index 4681cda03..7550a0975 100644 --- a/testing/example_scripts/unittest/test_setup_skip.py +++ b/testing/example_scripts/unittest/test_setup_skip.py @@ -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 diff --git a/testing/example_scripts/unittest/test_setup_skip_class.py b/testing/example_scripts/unittest/test_setup_skip_class.py index eae98287f..48f7e476f 100644 --- a/testing/example_scripts/unittest/test_setup_skip_class.py +++ b/testing/example_scripts/unittest/test_setup_skip_class.py @@ -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 diff --git a/testing/example_scripts/unittest/test_setup_skip_module.py b/testing/example_scripts/unittest/test_setup_skip_module.py index 43c24136e..eee4263d2 100644 --- a/testing/example_scripts/unittest/test_setup_skip_module.py +++ b/testing/example_scripts/unittest/test_setup_skip_module.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """setUpModule is always called, even if all tests in the module are skipped""" + import unittest diff --git a/testing/example_scripts/unittest/test_unittest_asynctest.py b/testing/example_scripts/unittest/test_unittest_asynctest.py index b3f03e325..e9b10171e 100644 --- a/testing/example_scripts/unittest/test_unittest_asynctest.py +++ b/testing/example_scripts/unittest/test_unittest_asynctest.py @@ -1,5 +1,6 @@ # mypy: allow-untyped-defs """Issue #7110""" + import asyncio from typing import List diff --git a/testing/io/test_wcwidth.py b/testing/io/test_wcwidth.py index 0989af00d..82503b830 100644 --- a/testing/io/test_wcwidth.py +++ b/testing/io/test_wcwidth.py @@ -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 diff --git a/testing/test_reports.py b/testing/test_reports.py index 2de5ae600..c6baeebc9 100644 --- a/testing/test_reports.py +++ b/testing/test_reports.py @@ -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 diff --git a/testing/test_runner_xunit.py b/testing/test_runner_xunit.py index 8076e20bc..587c9eb9f 100644 --- a/testing/test_runner_xunit.py +++ b/testing/test_runner_xunit.py @@ -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 diff --git a/testing/test_terminal.py b/testing/test_terminal.py index b311d6c9b..f49425109 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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 diff --git a/testing/typing_checks.py b/testing/typing_checks.py index a2ceabcbd..4b146a251 100644 --- a/testing/typing_checks.py +++ b/testing/typing_checks.py @@ -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