diff --git a/pytest_mypy_plugins/item.py b/pytest_mypy_plugins/item.py index 173809e..bfdf590 100644 --- a/pytest_mypy_plugins/item.py +++ b/pytest_mypy_plugins/item.py @@ -6,7 +6,17 @@ import sys import tempfile from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List, Optional, TextIO, Tuple, Union +from typing import ( + TYPE_CHECKING, + Any, + Dict, + List, + Literal, + Optional, + TextIO, + Tuple, + Union, +) import py import pytest @@ -18,9 +28,6 @@ from mypy.fscache import FileSystemCache from mypy.main import process_options -if TYPE_CHECKING: - from _pytest._code.code import _TracebackStyle - from pytest_mypy_plugins import configs, utils from pytest_mypy_plugins.collect import File, YamlTestFile from pytest_mypy_plugins.utils import ( @@ -30,6 +37,13 @@ fname_to_module, ) +if TYPE_CHECKING: + # pytest 8.3.0 renamed _TracebackStyle to TracebackStyle, but there is no syntax + # to assert what version you have using static conditions, so it has to be + # manually re-defined here. Once minimum supported pytest version is >= 8.3.0, + # the following can be replaced with `from _pytest._code.code import TracebackStyle` + TracebackStyle = Literal["long", "short", "line", "no", "native", "value", "auto"] + class TraceLastReprEntry(ReprEntry): def toterminal(self, tw: TerminalWriter) -> None: @@ -443,7 +457,7 @@ def prepare_config_file(self, execution_path: Path) -> Optional[str]: return None def repr_failure( - self, excinfo: ExceptionInfo[BaseException], style: Optional["_TracebackStyle"] = None + self, excinfo: ExceptionInfo[BaseException], style: Optional["TracebackStyle"] = None ) -> Union[str, TerminalRepr]: if excinfo.errisinstance(SystemExit): # We assume that before doing exit() (which raises SystemExit) we've printed