Elide pytest-internal paths for --fixtures#9281
Elide pytest-internal paths for --fixtures#9281The-Compiler merged 2 commits intopytest-dev:mainfrom
Conversation
|
cc @rahul-kumi if you want to take a look! |
src/_pytest/python.py
Outdated
| write_docstring(tw, doc.split("\n\n")[0] if verbose <= 0 else doc) | ||
| else: | ||
| tw.line(f" {loc}: no docstring available", red=True) | ||
| tw.line(f" no docstring available", red=True) |
There was a problem hiding this comment.
removed the location here as it seems redundant now that we always show the location anyways.
| loc = Path(getlocation(func, str(cwd))) | ||
| prefix = Path("...", "_pytest") | ||
| try: | ||
| return str(prefix / loc.relative_to(_PYTEST_DIR)) |
There was a problem hiding this comment.
How about we opt for relative to site packages if in site packages and/or relative to start dir if sensible
I believe the real bug is that bestrelpath fails to determine when the absolute path is actually shorter than the best relative one
There was a problem hiding this comment.
Do we have something already to check if a path is in site packages? From what I remember from things like hunter, getting a proper site packages path is quite a pain with differences between Python versions, distributions (Debian/Ubuntu and dist-packages), etc. etc.
I suppose bestrelpath could show an absolute path if that is shorter indeed. But given that it's used in various places I'm not sure if I want to introduce such a change...
There was a problem hiding this comment.
Oh: The path from my example above is relative and "correct", but I still believe the elided path is nicer for the output.
There was a problem hiding this comment.
The proposed solution is already a enhancement, let's take my comment as a follow-up
Before this PR:
with it:
Note that we still display the full path for fixtures from plugins, though. I think a fix for that would be a bit more involved, and probably not something for 7.0.
Fixes #8822