-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Elide pytest-internal paths for --fixtures #9281
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
Elide pytest-internal paths for --fixtures #9281
Conversation
cc @rahul-kumi if you want to take a look! |
src/_pytest/python.py
Outdated
doc = inspect.getdoc(fixturedef.func) | ||
if doc: | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the location here as it seems redundant now that we always show the location anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed solution is already a enhancement, let's take my comment as a follow-up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #9292 for the 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