Skip to content

Commit

Permalink
Change Node.reportinfo() return value from py.path to `str|os.Pat…
Browse files Browse the repository at this point in the history
…hLike[str]`

`reportinfo()` is the last remaining py.path-only code path in pytest,
i.e. the last piece holding back py.path deprecation. The problem with
it is that plugins/users use it from both sides -- implementing it
(returning the value) and using it (using the return value). Dealing
with implementers is easy enough -- allow to return `os.PathLike[str]`.
But for callers who expect strictly `py.path` this will break and
there's not really a good way to provide backward compat for this.

From analyzing a corpus of 680 pytest plugins, the vast majority of
`reportinfo` appearances are implementations, and the few callers don't
actually access the path part of the return tuple.

As for test suites that might access `reportinfo` (e.g. using
`request.node.reportinfo()` or other ways), that is much harder to
survey, but from the ones I searched, I only found case
(`pytest_teamcity`, but even then it uses `str(fspath)` so is unlikely
to be affected in practice). They are better served with using
`node.location` or `node.path` directly.

Therefore, just break it and change the return type to
`str|os.PathLike[str]`.

Refs ipython#7259.
  • Loading branch information
bluetech authored and Kojoley committed Feb 8, 2022
1 parent 0e009a0 commit e3125d3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions IPython/testing/plugin/pytest_ipdoctest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Discover and run doctests in modules and test files."""
import bdb
import inspect
import os
import platform
import sys
import traceback
Expand Down Expand Up @@ -28,7 +29,6 @@
from _pytest._code.code import ReprFileLocation
from _pytest._code.code import TerminalRepr
from _pytest._io import TerminalWriter
from _pytest.compat import legacy_path
from _pytest.compat import safe_getattr
from _pytest.config import Config
from _pytest.config.argparsing import Parser
Expand Down Expand Up @@ -371,9 +371,9 @@ def repr_failure( # type: ignore[override]
reprlocation_lines.append((reprlocation, lines))
return ReprFailDoctest(reprlocation_lines)

def reportinfo(self):
def reportinfo(self) -> Tuple[Union["os.PathLike[str]", str], Optional[int], str]:
assert self.dtest is not None
return legacy_path(self.path), self.dtest.lineno, "[doctest] %s" % self.name
return self.path, self.dtest.lineno, "[doctest] %s" % self.name


def _get_flag_lookup() -> Dict[str, int]:
Expand Down

0 comments on commit e3125d3

Please sign in to comment.