Skip to content

Work-around pytest 8.3.0 renaming _TracebackStyle #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions pytest_mypy_plugins/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading