From e577541b4bdcab19f68418c8a98c1a6d2e33999f Mon Sep 17 00:00:00 2001 From: jakkdl Date: Fri, 1 Dec 2023 18:19:15 +0100 Subject: [PATCH] import exceptiongroup on <3.11 --- src/_pytest/python_api.py | 9 +++++---- testing/python/expected_exception_group.py | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 72973e2cf..82fde59de 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -1,6 +1,7 @@ import math import pprint import re +import sys from collections.abc import Collection from collections.abc import Sized from decimal import Decimal @@ -25,16 +26,16 @@ from typing import TYPE_CHECKING from typing import TypeVar from typing import Union -if TYPE_CHECKING: - from typing_extensions import TypeAlias, TypeGuard - - import _pytest._code from _pytest.compat import STRING_TYPES from _pytest.outcomes import fail if TYPE_CHECKING: from numpy import ndarray + from typing_extensions import TypeAlias, TypeGuard + +if sys.version_info < (3, 11): + from exceptiongroup import BaseExceptionGroup def _non_numeric_type_error(value, at: Optional[str]) -> TypeError: diff --git a/testing/python/expected_exception_group.py b/testing/python/expected_exception_group.py index 5d74b7361..c33e9d048 100644 --- a/testing/python/expected_exception_group.py +++ b/testing/python/expected_exception_group.py @@ -1,3 +1,4 @@ +import sys from typing import TYPE_CHECKING import pytest @@ -9,6 +10,9 @@ from _pytest.python_api import Matcher if TYPE_CHECKING: from typing_extensions import assert_type +if sys.version_info < (3, 11): + from exceptiongroup import ExceptionGroup + class TestExpectedExceptionGroup: def test_expected_exception_group(self) -> None: