Skip to content
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

2 small cleanups #12256

Merged
merged 2 commits into from Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/_pytest/_code/code.py
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/config/argparsing.py
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/fixtures.py
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/nodes.py
Expand Up @@ -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])
4 changes: 2 additions & 2 deletions src/_pytest/pathlib.py
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/runner.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion testing/code/test_excinfo.py
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion testing/test_runner.py
Expand Up @@ -23,7 +23,7 @@
import pytest


if sys.version_info[:2] < (3, 11):
if sys.version_info < (3, 11):
from exceptiongroup import ExceptionGroup


Expand Down
2 changes: 1 addition & 1 deletion testing/test_skipping.py
Expand Up @@ -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*",
Expand Down