| 1 |
# mypy: allow-untyped-defs |
| 2 |
"""File for checking typing issues. |
| 3 |
|
| 4 |
This file is not executed, it is only checked by mypy to ensure that |
| 5 |
none of the code triggers any mypy errors. |
| 6 |
""" |
| 7 |
|
| 8 |
from __future__ import annotations |
| 9 |
|
| 10 |
import contextlib |
| 11 |
from typing import Literal |
| 12 |
|
| 13 |
from typing_extensions import assert_type |
| 14 |
|
| 15 |
import pytest |
| 16 |
from pytest import MonkeyPatch |
| 17 |
from pytest import ScopeName |
| 18 |
from pytest import TestReport |
| 19 |
|
| 20 |
|
| 21 |
# Issue #7488. |
| 22 |
@pytest.mark.xfail(raises=RuntimeError) |
| 23 |
def check_mark_xfail_raises() -> None: |
| 24 |
pass |
| 25 |
|
| 26 |
|
| 27 |
# Issue #7494. |
| 28 |
@pytest.fixture(params=[(0, 0), (1, 1)], ids=lambda x: str(x[0])) |
| 29 |
def check_fixture_ids_callable() -> None: |
| 30 |
pass |
| 31 |
|
| 32 |
|
| 33 |
# Issue #7494. |
| 34 |
@pytest.mark.parametrize("func", [str, int], ids=lambda x: str(x.__name__)) |
| 35 |
def check_parametrize_ids_callable(func) -> None: |
| 36 |
pass |
| 37 |
|
| 38 |
|
| 39 |
# Issue #10999. |
| 40 |
def check_monkeypatch_typeddict(monkeypatch: MonkeyPatch) -> None: |
| 41 |
from typing import TypedDict |
| 42 |
|
| 43 |
class Foo(TypedDict): |
| 44 |
x: int |
| 45 |
y: float |
| 46 |
|
| 47 |
a: Foo = {"x": 1, "y": 3.14} |
| 48 |
monkeypatch.setitem(a, "x", 2) |
| 49 |
monkeypatch.delitem(a, "y") |
| 50 |
|
| 51 |
|
| 52 |
def check_raises_is_a_context_manager(val: bool) -> None: |
| 53 |
with pytest.raises(RuntimeError) if val else contextlib.nullcontext() as excinfo: |
| 54 |
pass |
| 55 |
assert_type(excinfo, pytest.ExceptionInfo[RuntimeError] | None) |
| 56 |
|
| 57 |
|
| 58 |
# Issue #12941. |
| 59 |
def check_testreport_attributes(report: TestReport) -> None: |
| 60 |
assert_type(report.when, Literal["setup", "call", "teardown"]) |
| 61 |
assert_type(report.location, tuple[str, int | None, str]) |
| 62 |
|
| 63 |
|
| 64 |
# Issue #14234. |
| 65 |
@pytest.mark.parametrize("x", [1, 2], ids=[pytest.HIDDEN_PARAM, "visible"]) |
| 66 |
def test_hidden_param(x: int) -> None: |
| 67 |
pass |
| 68 |
|
| 69 |
|
| 70 |
# Issue #14137. |
| 71 |
def check_scope_typing() -> None: |
| 72 |
|
| 73 |
custom_scope: ScopeName = "function" |
| 74 |
assert_type(custom_scope, ScopeName) |
| 75 |
|
| 76 |
|
| 77 |
# Issue #14606. |
| 78 |
@pytest.mark.parametrize("x", [ImportError, AttributeError]) |
| 79 |
def check_mypy_bug_with_argvalues(x) -> None: |
| 80 |
pass |