Merge pull request #12467 from RonnyPfannschmidt/ronny/new-annotations-try-2

from __future__ import annotations + migrate
This commit is contained in:
Ronny Pfannschmidt
2024-06-21 10:24:56 +02:00
committed by GitHub
244 changed files with 2016 additions and 1805 deletions

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import contextlib
import multiprocessing
import os

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import dataclasses
import importlib.metadata
import os

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import re
import sys
from types import FrameType

View File

@@ -1,9 +1,10 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import dataclasses
import re
import sys
from typing import Generator
from typing import List
from _pytest.monkeypatch import MonkeyPatch
from _pytest.pytester import Pytester
@@ -190,22 +191,22 @@ def color_mapping():
NO_COLORS = {k: "" for k in COLORS.keys()}
@classmethod
def format(cls, lines: List[str]) -> List[str]:
def format(cls, lines: list[str]) -> list[str]:
"""Straightforward replacement of color names to their ASCII codes."""
return [line.format(**cls.COLORS) for line in lines]
@classmethod
def format_for_fnmatch(cls, lines: List[str]) -> List[str]:
def format_for_fnmatch(cls, lines: list[str]) -> list[str]:
"""Replace color names for use with LineMatcher.fnmatch_lines"""
return [line.format(**cls.COLORS).replace("[", "[[]") for line in lines]
@classmethod
def format_for_rematch(cls, lines: List[str]) -> List[str]:
def format_for_rematch(cls, lines: list[str]) -> list[str]:
"""Replace color names for use with LineMatcher.re_match_lines"""
return [line.format(**cls.RE_COLORS) for line in lines]
@classmethod
def strip_colors(cls, lines: List[str]) -> List[str]:
def strip_colors(cls, lines: list[str]) -> list[str]:
"""Entirely remove every color code"""
return [line.format(**cls.NO_COLORS) for line in lines]

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from pathlib import Path
import re
import sys

View File

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

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_init():
pass

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_foo():
pass

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def pytest_ignore_collect(collection_path):
return False

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test():
pass

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_init():
pass

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_foo():
pass

View File

@@ -1,2 +1,5 @@
from __future__ import annotations
class pytest_something:
pass

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_foo():
pass

View File

@@ -1,4 +1,7 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def pytest_configure(config):
import pytest

View File

@@ -1,5 +1,7 @@
# mypy: allow-untyped-defs
# content of conftest.py
from __future__ import annotations
import json
import pytest

View File

@@ -1,4 +1,7 @@
# mypy: allow-untyped-defs
# content of test_first.py
from __future__ import annotations
def test_1():
pass

View File

@@ -1,4 +1,7 @@
# mypy: allow-untyped-defs
# content of test_second.py
from __future__ import annotations
def test_2():
pass

View File

@@ -1,4 +1,7 @@
# mypy: allow-untyped-defs
# content of test_third.py
from __future__ import annotations
def test_3():
pass

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import field

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import field

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import field

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import field

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import InitVar

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from dataclasses import dataclass

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import field

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_this_is_ignored():
assert True

View File

@@ -1,4 +1,7 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_doc():
"""
>>> 10 > 5

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test():
pass

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_1(arg1):
pass

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_2(arg2):
pass

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_spam(spam):
assert spam == "spamspam"

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_hello():
pass

View File

@@ -1,7 +1,7 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pprint
from typing import List
from typing import Tuple
import pytest
@@ -16,7 +16,7 @@ def pytest_generate_tests(metafunc):
@pytest.fixture(scope="session")
def checked_order():
order: List[Tuple[str, str, str]] = []
order: list[tuple[str, str, str]] = []
yield order
pprint.pprint(order)

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import argparse
import pathlib

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_x():
pass

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import unittest
import pytest

View File

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

View File

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

View File

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

View File

@@ -1,9 +1,10 @@
# mypy: allow-untyped-defs
from typing import List
from __future__ import annotations
from unittest import IsolatedAsyncioTestCase
teardowns: List[None] = []
teardowns: list[None] = []
class AsyncArguments(IsolatedAsyncioTestCase):

View File

@@ -1,13 +1,14 @@
# mypy: allow-untyped-defs
"""Issue #7110"""
from __future__ import annotations
import asyncio
from typing import List
import asynctest
teardowns: List[None] = []
teardowns: list[None] = []
class Test(asynctest.TestCase):

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import unittest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import warnings
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import warnings
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from test_1 import func

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from _pytest.pytester import Pytester

View File

@@ -1,5 +1,8 @@
"""Generate an executable with pytest runner embedded using PyInstaller."""
from __future__ import annotations
if __name__ == "__main__":
import subprocess

View File

@@ -3,6 +3,9 @@ This is the script that is actually frozen into an executable: simply executes
pytest main().
"""
from __future__ import annotations
if __name__ == "__main__":
import sys

View File

@@ -1,4 +1,7 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_upper():
assert "foo".upper() == "FOO"

View File

@@ -3,6 +3,9 @@ Called by tox.ini: uses the generated executable to run the tests in ./tests/
directory.
"""
from __future__ import annotations
if __name__ == "__main__":
import os
import sys

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from collections import ChainMap
from collections import Counter
from collections import defaultdict

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from _pytest._io.saferepr import DEFAULT_REPR_MAX_SIZE
from _pytest._io.saferepr import saferepr
from _pytest._io.saferepr import saferepr_unlimited

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import io
import os
from pathlib import Path
@@ -6,7 +8,6 @@ import re
import shutil
import sys
from typing import Generator
from typing import Optional
from unittest import mock
from _pytest._io import terminalwriter
@@ -166,7 +167,7 @@ def test_attr_hasmarkup() -> None:
assert "\x1b[0m" in s
def assert_color(expected: bool, default: Optional[bool] = None) -> None:
def assert_color(expected: bool, default: bool | None = None) -> None:
file = io.StringIO()
if default is None:
default = not expected

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from _pytest._io.wcwidth import wcswidth
from _pytest._io.wcwidth import wcwidth
import pytest

View File

@@ -1,5 +1,7 @@
# mypy: disable-error-code="attr-defined"
# mypy: disallow-untyped-defs
from __future__ import annotations
import logging
from typing import Iterator

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import logging
from typing import Any

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import io
import os
import re

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from pytest_bdd import given
from pytest_bdd import scenario
from pytest_bdd import then

View File

@@ -1 +1,4 @@
from __future__ import annotations
SECRET_KEY = "mysecret"

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import anyio
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import asyncio
import pytest

View File

@@ -1,3 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
def test_mocker(mocker):
mocker.MagicMock()

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import unittest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import trio
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest_twisted
from twisted.internet.task import deferLater

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import pytest

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from contextlib import contextmanager
from decimal import Decimal
from fractions import Fraction
@@ -6,7 +8,6 @@ from math import sqrt
import operator
from operator import eq
from operator import ne
from typing import Optional
from _pytest.pytester import Pytester
from _pytest.python_api import _recursive_sequence_map
@@ -415,9 +416,7 @@ class TestApprox:
(-1e100, -1e100),
],
)
def test_negative_tolerance(
self, rel: Optional[float], abs: Optional[float]
) -> None:
def test_negative_tolerance(self, rel: float | None, abs: float | None) -> None:
# Negative tolerances are not allowed.
with pytest.raises(ValueError):
1.1 == approx(1, rel, abs)

View File

@@ -1,9 +1,10 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import os
import sys
import textwrap
from typing import Any
from typing import Dict
import _pytest._code
from _pytest.config import ExitCode
@@ -1129,7 +1130,7 @@ class TestTracebackCutting:
tb = None
try:
ns: Dict[str, Any] = {}
ns: dict[str, Any] = {}
exec("def foo(): raise ValueError", ns)
ns["foo"]()
except ValueError:

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import os
from pathlib import Path
import sys
@@ -4514,7 +4516,7 @@ def test_fixture_named_request(pytester: Pytester) -> None:
result.stdout.fnmatch_lines(
[
"*'request' is a reserved word for fixtures, use another name:",
" *test_fixture_named_request.py:6",
" *test_fixture_named_request.py:8",
]
)

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from _pytest._code import getfslineno
from _pytest.fixtures import getfixturemarker
from _pytest.pytester import Pytester

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import dataclasses
import itertools
import re
@@ -8,11 +10,7 @@ from typing import Any
from typing import cast
from typing import Dict
from typing import Iterator
from typing import List
from typing import Optional
from typing import Sequence
from typing import Tuple
from typing import Union
import hypothesis
from hypothesis import strategies
@@ -35,7 +33,7 @@ class TestMetafunc:
# on the funcarg level, so we don't need a full blown
# initialization.
class FuncFixtureInfoMock:
name2fixturedefs: Dict[str, List[fixtures.FixtureDef[object]]] = {}
name2fixturedefs: dict[str, list[fixtures.FixtureDef[object]]] = {}
def __init__(self, names):
self.names_closure = names
@@ -101,7 +99,7 @@ class TestMetafunc:
def __repr__(self):
return "Exc(from_gen)"
def gen() -> Iterator[Union[int, None, Exc]]:
def gen() -> Iterator[int | None | Exc]:
yield 0
yield None
yield Exc()
@@ -346,7 +344,7 @@ class TestMetafunc:
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
values: List[Tuple[str, Any, str]] = [
values: list[tuple[str, Any, str]] = [
("ação", MockConfig({option: True}), "ação"),
("ação", MockConfig({option: False}), "a\\xe7\\xe3o"),
]
@@ -516,7 +514,7 @@ class TestMetafunc:
def test_idmaker_idfn(self) -> None:
"""#351"""
def ids(val: object) -> Optional[str]:
def ids(val: object) -> str | None:
if isinstance(val, Exception):
return repr(val)
return None
@@ -579,7 +577,7 @@ class TestMetafunc:
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
values: List[Tuple[Any, str]] = [
values: list[tuple[Any, str]] = [
(MockConfig({option: True}), "ação"),
(MockConfig({option: False}), "a\\xe7\\xe3o"),
]
@@ -617,7 +615,7 @@ class TestMetafunc:
option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
values: List[Tuple[Any, str]] = [
values: list[tuple[Any, str]] = [
(MockConfig({option: True}), "ação"),
(MockConfig({option: False}), "a\\xe7\\xe3o"),
]
@@ -1748,9 +1746,9 @@ class TestMetafuncFunctionalAuto:
self, pytester: Pytester, monkeypatch
) -> None:
"""Integration test for (#3941)"""
class_fix_setup: List[object] = []
class_fix_setup: list[object] = []
monkeypatch.setattr(sys, "class_fix_setup", class_fix_setup, raising=False)
func_fix_setup: List[object] = []
func_fix_setup: list[object] = []
monkeypatch.setattr(sys, "func_fix_setup", func_fix_setup, raising=False)
pytester.makepyfile(

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import re
import sys

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from _pytest.pytester import Pytester

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
from pathlib import Path
import subprocess
import sys

View File

@@ -1,11 +1,11 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import sys
import textwrap
from typing import Any
from typing import List
from typing import MutableSequence
from typing import NamedTuple
from typing import Optional
import attr
@@ -19,7 +19,7 @@ from _pytest.pytester import Pytester
import pytest
def mock_config(verbose: int = 0, assertion_override: Optional[int] = None):
def mock_config(verbose: int = 0, assertion_override: int | None = None):
class TerminalWriter:
def _highlight(self, source, lexer="python"):
return source
@@ -28,7 +28,7 @@ def mock_config(verbose: int = 0, assertion_override: Optional[int] = None):
def get_terminal_writer(self):
return TerminalWriter()
def get_verbosity(self, verbosity_type: Optional[str] = None) -> int:
def get_verbosity(self, verbosity_type: str | None = None) -> int:
if verbosity_type is None:
return verbose
if verbosity_type == _Config.VERBOSITY_ASSERTIONS:
@@ -369,12 +369,12 @@ class TestBinReprIntegration:
result.stdout.fnmatch_lines(["*test_hello*FAIL*", "*test_check*PASS*"])
def callop(op: str, left: Any, right: Any, verbose: int = 0) -> Optional[List[str]]:
def callop(op: str, left: Any, right: Any, verbose: int = 0) -> list[str] | None:
config = mock_config(verbose=verbose)
return plugin.pytest_assertrepr_compare(config, op, left, right)
def callequal(left: Any, right: Any, verbose: int = 0) -> Optional[List[str]]:
def callequal(left: Any, right: Any, verbose: int = 0) -> list[str] | None:
return callop("==", left, right, verbose)
@@ -1316,7 +1316,7 @@ class TestTruncateExplanation:
LINES_IN_TRUNCATION_MSG = 2
def test_doesnt_truncate_when_input_is_empty_list(self) -> None:
expl: List[str] = []
expl: list[str] = []
result = truncate._truncate_explanation(expl, max_lines=8, max_chars=100)
assert result == expl

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import ast
import errno
from functools import partial
@@ -12,12 +14,8 @@ import stat
import sys
import textwrap
from typing import cast
from typing import Dict
from typing import Generator
from typing import List
from typing import Mapping
from typing import Optional
from typing import Set
from unittest import mock
import zipfile
@@ -45,13 +43,13 @@ def rewrite(src: str) -> ast.Module:
def getmsg(
f, extra_ns: Optional[Mapping[str, object]] = None, *, must_pass: bool = False
) -> Optional[str]:
f, extra_ns: Mapping[str, object] | None = None, *, must_pass: bool = False
) -> str | None:
"""Rewrite the assertions in f, run it, and get the failure message."""
src = "\n".join(_pytest._code.Code.from_function(f).source().lines)
mod = rewrite(src)
code = compile(mod, "<test>", "exec")
ns: Dict[str, object] = {}
ns: dict[str, object] = {}
if extra_ns is not None:
ns.update(extra_ns)
exec(code, ns)
@@ -1638,8 +1636,8 @@ class TestEarlyRewriteBailout:
"""
import importlib.machinery
self.find_spec_calls: List[str] = []
self.initial_paths: Set[Path] = set()
self.find_spec_calls: list[str] = []
self.initial_paths: set[Path] = set()
class StubSession:
_initialpaths = self.initial_paths
@@ -2059,7 +2057,7 @@ class TestReprSizeVerbosity:
)
def test_get_maxsize_for_saferepr(self, verbose: int, expected_size) -> None:
class FakeConfig:
def get_verbosity(self, verbosity_type: Optional[str] = None) -> int:
def get_verbosity(self, verbosity_type: str | None = None) -> int:
return verbose
config = FakeConfig()

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from enum import auto
from enum import Enum
import os
@@ -5,9 +7,7 @@ from pathlib import Path
import shutil
from typing import Any
from typing import Generator
from typing import List
from typing import Sequence
from typing import Tuple
from _pytest.compat import assert_never
from _pytest.config import ExitCode
@@ -579,7 +579,7 @@ class TestLastFailed:
def rlf(
fail_import: int, fail_run: int, args: Sequence[str] = ()
) -> Tuple[Any, Any]:
) -> tuple[Any, Any]:
monkeypatch.setenv("FAILIMPORT", str(fail_import))
monkeypatch.setenv("FAILTEST", str(fail_run))
@@ -693,7 +693,7 @@ class TestLastFailed:
else:
assert "rerun previous" in result.stdout.str()
def get_cached_last_failed(self, pytester: Pytester) -> List[str]:
def get_cached_last_failed(self, pytester: Pytester) -> list[str]:
config = pytester.parseconfigure()
assert config.cache is not None
return sorted(config.cache.get("cache/lastfailed", {}))

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import contextlib
import io
from io import UnsupportedOperation

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import os
from pathlib import Path
import pprint
@@ -6,8 +8,6 @@ import shutil
import sys
import tempfile
import textwrap
from typing import List
from typing import Type
from _pytest.assertion.util import running_on_ci
from _pytest.config import ExitCode
@@ -536,7 +536,7 @@ class TestSession:
assert len(colitems) == 1
assert colitems[0].path == topdir
def get_reported_items(self, hookrec: HookRecorder) -> List[Item]:
def get_reported_items(self, hookrec: HookRecorder) -> list[Item]:
"""Return pytest.Item instances reported by the pytest_collectreport hook"""
calls = hookrec.getcalls("pytest_collectreport")
return [
@@ -1885,7 +1885,7 @@ def test_do_not_collect_symlink_siblings(
)
def test_respect_system_exceptions(
pytester: Pytester,
exception_class: Type[BaseException],
exception_class: type[BaseException],
msg: str,
):
head = "Before exception"

View File

@@ -1,11 +1,12 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import enum
from functools import cached_property
from functools import partial
from functools import wraps
import sys
from typing import TYPE_CHECKING
from typing import Union
from _pytest.compat import _PytestWrapper
from _pytest.compat import assert_never
@@ -216,7 +217,7 @@ def test_cached_property() -> None:
def test_assert_never_union() -> None:
x: Union[int, str] = 10
x: int | str = 10
if isinstance(x, int):
pass

View File

@@ -1,4 +1,6 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import dataclasses
import importlib.metadata
import os
@@ -7,12 +9,7 @@ import re
import sys
import textwrap
from typing import Any
from typing import Dict
from typing import List
from typing import Sequence
from typing import Tuple
from typing import Type
from typing import Union
import _pytest._code
from _pytest.config import _get_plugin_specs_as_list
@@ -633,7 +630,7 @@ class TestConfigCmdlineParsing:
class TestConfigAPI:
def test_config_trace(self, pytester: Pytester) -> None:
config = pytester.parseconfig()
values: List[str] = []
values: list[str] = []
config.trace.root.setwriter(values.append)
config.trace("hello")
assert len(values) == 1
@@ -996,7 +993,7 @@ class TestConfigFromdictargs:
def test_invocation_params_args(self, _sys_snapshot) -> None:
"""Show that fromdictargs can handle args in their "orig" format"""
option_dict: Dict[str, object] = {}
option_dict: dict[str, object] = {}
args = ["-vvvv", "-s", "a", "b"]
config = Config.fromdictargs(option_dict, args)
@@ -1210,7 +1207,7 @@ def test_plugin_preparse_prevents_setuptools_loading(
def test_disable_plugin_autoload(
pytester: Pytester,
monkeypatch: MonkeyPatch,
parse_args: Union[Tuple[str, str], Tuple[()]],
parse_args: tuple[str, str] | tuple[()],
should_load: bool,
) -> None:
class DummyEntryPoint:
@@ -1304,7 +1301,7 @@ def test_invalid_options_show_extra_information(pytester: Pytester) -> None:
],
)
def test_consider_args_after_options_for_rootdir(
pytester: Pytester, args: List[str]
pytester: Pytester, args: list[str]
) -> None:
"""
Consider all arguments in the command-line for rootdir
@@ -2241,7 +2238,7 @@ def test_strtobool() -> None:
],
)
def test_parse_warning_filter(
arg: str, escape: bool, expected: Tuple[str, str, Type[Warning], str, int]
arg: str, escape: bool, expected: tuple[str, str, type[Warning], str, int]
) -> None:
assert parse_warning_filter(arg, escape=escape) == expected

Some files were not shown because too many files have changed in this diff Show More