diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 3b4a62a4fa0..c65ce79f7e5 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -52,7 +52,7 @@ from _pytest.pathlib import bestrelpath -if sys.version_info[:2] < (3, 11): +if sys.version_info < (3, 11): from exceptiongroup import BaseExceptionGroup _TracebackStyle = Literal["long", "short", "line", "no", "native", "value", "auto"] @@ -703,7 +703,7 @@ def _stringify_exception(self, exc: BaseException) -> str: # Workaround for https://github.com/python/cpython/issues/98778 on # Python <= 3.9, and some 3.10 and 3.11 patch versions. HTTPError = getattr(sys.modules.get("urllib.error", None), "HTTPError", ()) - if sys.version_info[:2] <= (3, 11) and isinstance(exc, HTTPError): + if sys.version_info < (3, 12) and isinstance(exc, HTTPError): notes = [] else: raise diff --git a/src/_pytest/config/argparsing.py b/src/_pytest/config/argparsing.py index 95dc28d4a16..9006351af72 100644 --- a/src/_pytest/config/argparsing.py +++ b/src/_pytest/config/argparsing.py @@ -448,7 +448,7 @@ def parse_args( # type: ignore getattr(parsed, FILE_OR_DIR).extend(unrecognized) return parsed - if sys.version_info[:2] < (3, 9): # pragma: no cover + if sys.version_info < (3, 9): # pragma: no cover # Backport of https://github.com/python/cpython/pull/14316 so we can # disable long --argument abbreviations without breaking short flags. def _parse_optional( diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 5303948c4d5..656160ff7dc 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -69,7 +69,7 @@ from _pytest.scope import Scope -if sys.version_info[:2] < (3, 11): +if sys.version_info < (3, 11): from exceptiongroup import BaseExceptionGroup diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 1b91bdb6e43..974d756a2be 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -765,7 +765,7 @@ def location(self) -> Tuple[str, Optional[int], str]: and lineno is a 0-based line number. """ location = self.reportinfo() - path = absolutepath(os.fspath(location[0])) + path = absolutepath(location[0]) relfspath = self.session._node_location_to_relpath(path) assert type(location[2]) is str return (relfspath, location[1], location[2]) diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index 190d9dd8ce6..e14c2acd328 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -924,13 +924,13 @@ def visit( yield from visit(entry.path, recurse) -def absolutepath(path: Union[Path, str]) -> Path: +def absolutepath(path: "Union[str, os.PathLike[str]]") -> Path: """Convert a path to an absolute path using os.path.abspath. Prefer this over Path.resolve() (see #6523). Prefer this over Path.absolute() (not public, doesn't normalize). """ - return Path(os.path.abspath(str(path))) + return Path(os.path.abspath(path)) def commonpath(path1: Path, path2: Path) -> Optional[Path]: diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 3f706b927c8..9bc544ea742 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -39,7 +39,7 @@ from _pytest.outcomes import TEST_OUTCOME -if sys.version_info[:2] < (3, 11): +if sys.version_info < (3, 11): from exceptiongroup import BaseExceptionGroup if TYPE_CHECKING: diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 419c11abcc0..dd4bd22c8b8 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -28,7 +28,7 @@ if TYPE_CHECKING: from _pytest._code.code import _TracebackStyle -if sys.version_info[:2] < (3, 11): +if sys.version_info < (3, 11): from exceptiongroup import ExceptionGroup diff --git a/testing/test_runner.py b/testing/test_runner.py index 6e034e94532..8b41ec28a38 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -23,7 +23,7 @@ import pytest -if sys.version_info[:2] < (3, 11): +if sys.version_info < (3, 11): from exceptiongroup import ExceptionGroup diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 3f1c83f5bbe..a1511b26d1c 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -1146,7 +1146,7 @@ def test_func(): if pypy_version_info is not None and pypy_version_info < (6,): markline = markline[1:] - if sys.version_info[:2] >= (3, 10): + if sys.version_info >= (3, 10): expected = [ "*ERROR*test_nameerror*", "*asd*",