Skip to content

Issue 7076 - relative path to invocation dir (not rootdir) - #7158

Merged
nicoddemus merged 4 commits into
pytest-dev:masterfrom
CarycaKatarzyna:issue_7076
May 8, 2020
Merged

Issue 7076 - relative path to invocation dir (not rootdir)#7158
nicoddemus merged 4 commits into
pytest-dev:masterfrom
CarycaKatarzyna:issue_7076

Conversation

@CarycaKatarzyna

Copy link
Copy Markdown
Contributor

My second approach to issue #7076 (previous pull request - #7095 ). I've changed the path to absolute by joining with the rootdir. Next it is changed into relative to the invocation_dir in this place:

fspath = startdir.bestrelpath(py.path.local(fspath))

I'm also adding a test that runs with rootdir not equal to invocation_dir.

Fixes #7076.

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @CarycaKatarzyna!

This approach looks good to me, thanks.

I was about to comment to use reportinfo() instead of location in skipping.py, but I had already tested it locally so decided to just push the change myself. 👍

Comment thread src/_pytest/skipping.py Outdated
@@ -169,6 +169,7 @@ def pytest_runtest_makereport(item, call):
# the location of where the skip exception was raised within pytest
_, _, reason = rep.longrepr
filename, line = item.location[:2]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit weird that location explicitly returns a relative path to rootdir:

pytest/src/_pytest/nodes.py

Lines 586 to 595 in 80e5098

@cached_property
def location(self) -> Tuple[str, Optional[int], str]:
location = self.reportinfo()
if isinstance(location[0], py.path.local):
fspath = location[0]
else:
fspath = py.path.local(location[0])
relfspath = self.session._node_location_to_relpath(fspath)
assert type(location[2]) is str
return (relfspath, location[1], location[2])

To me it would make more sense to always return the full path, and the user can decide to make that path relative to whatever he wants.

This is not really related to the PR, just some musings after looking at the code.

@nicoddemus
nicoddemus merged commit 9657798 into pytest-dev:master May 8, 2020
@CarycaKatarzyna
CarycaKatarzyna deleted the issue_7076 branch May 8, 2020 19:56
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.

Wrong relative path in skip report when tested file is upper than invocation directory

2 participants