Skip to content

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

Merged
merged 2 commits into from
Nov 10, 2021

Conversation

The-Compiler
Copy link
Member

@The-Compiler The-Compiler commented Nov 8, 2021

Before this PR:

caplog -- .tox/py39-pyqt515/lib/python3.9/site-packages/_pytest/logging.py:476
    Access and control log capturing

with it:

caplog -- .../_pytest/logging.py:491
    Access and control log capturing.

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

@The-Compiler The-Compiler changed the title Pretty-fixture-path Elide pytest-internal paths for --fixtures Nov 8, 2021
@The-Compiler
Copy link
Member Author

cc @rahul-kumi if you want to take a look!

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)
Copy link
Member Author

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.

Copy link
Member

@nicoddemus nicoddemus left a 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))
Copy link
Member

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

Copy link
Member Author

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...

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate cleaning up of --fixture path outputs
3 participants