Skip to content
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

fix 4425: resolve --basetemp to absolute paths #4427

Merged
merged 5 commits into from
Nov 22, 2018

Conversation

RonnyPfannschmidt
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt commented Nov 20, 2018

fixes #4425

@codecov
Copy link

codecov bot commented Nov 20, 2018

Codecov Report

Merging #4427 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #4427      +/-   ##
=========================================
- Coverage    95.9%   95.9%   -0.01%     
=========================================
  Files         111     111              
  Lines       25008   25027      +19     
  Branches     2438    2442       +4     
=========================================
+ Hits        23984   24001      +17     
- Misses        723     724       +1     
- Partials      301     302       +1
Flag Coverage Δ
#docs 30.17% <15.38%> (+0.07%) ⬆️
#doctesting 30.17% <15.38%> (+0.07%) ⬆️
#linting 30.17% <15.38%> (+0.07%) ⬆️
#linux 95.73% <100%> (-0.01%) ⬇️
#nobyte 92.65% <100%> (ø) ⬆️
#numpy 93.42% <100%> (-0.02%) ⬇️
#pexpect 41.84% <19.23%> (-0.06%) ⬇️
#py27 94.03% <100%> (ø) ⬆️
#py34 92.17% <100%> (+0.06%) ⬆️
#py35 92.19% <100%> (+0.06%) ⬆️
#py36 92.21% <100%> (+0.06%) ⬆️
#py37 94.1% <100%> (-0.01%) ⬇️
#trial 93.42% <100%> (-0.02%) ⬇️
#windows 94.11% <100%> (ø) ⬆️
#xdist 93.96% <100%> (ø) ⬆️
Impacted Files Coverage Δ
src/_pytest/monkeypatch.py 93.87% <100%> (+0.12%) ⬆️
src/_pytest/tmpdir.py 100% <100%> (ø) ⬆️
testing/test_tmpdir.py 98.86% <100%> (+0.11%) ⬆️
src/_pytest/capture.py 93.42% <0%> (-0.46%) ⬇️
src/_pytest/terminal.py 92.84% <0%> (-0.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45c33c4...5f1d692. Read the comment docs.

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.

Aside from my nitpick remarks, LGTM. Feel free to merge this at your discretion. 👍

@@ -25,12 +26,29 @@ def test_ensuretemp(recwarn):
assert d1.check(dir=1)


@attr.s
class FakeConfig(object):
Copy link
Member

Choose a reason for hiding this comment

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

TBH not sure if this fake actually improves things... the "option returns self" and get are quite the hack. 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

its indeed quite a hack, we cant make a sane config object for use in such cases

@@ -40,6 +58,14 @@ def test_mktemp(self, testdir):
assert tmp2.relto(t.getbasetemp()).startswith("this")
assert tmp2 != tmp

def test_tmppath_relative_basetemp_absolute(self, tmp_path, monkeypatch):
from _pytest.tmpdir import TempPathFactory
Copy link
Member

Choose a reason for hiding this comment

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

I would add a docstring and a reference to the bug. 👍

Unfortunately it seems there is a difference in resolve() behavior depending
on the platform
@nicoddemus
Copy link
Member

Found a discussion about Path.absolute(), it is really public by accident.

Fix the os.path.abspath call to handle the case where the parameter is already a path, in Path-clueless versions.

@RonnyPfannschmidt
Copy link
Member Author

restarted the build, travis was broken

@nicoddemus
Copy link
Member

Weird, on MacOS the test fails, here's the exception formatted for readability:

PosixPath('/private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pytest-of-travis/pytest-0/test_tmppath_relative_basetemp0/hello')
 == 
PosixPath('/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pytest-of-travis/pytest-0/test_tmppath_relative_basetemp0') / 'hello'

Seems to be symlink-related...

@RonnyPfannschmidt
Copy link
Member Author

it is symlink related, other projects see the same issue

we can use resolve on the resulting paths

@nicoddemus
Copy link
Member

ahh good catch!

@nicoddemus nicoddemus merged commit 9424d88 into pytest-dev:master Nov 22, 2018
@pllim
Copy link
Contributor

pllim commented Nov 22, 2018

Hello. I am looking forward to this fix. Which release is it going to be in? Thanks.

@RonnyPfannschmidt
Copy link
Member Author

the next release in any case

@RonnyPfannschmidt RonnyPfannschmidt deleted the fix-4425 branch November 22, 2018 19:18
@pllim
Copy link
Contributor

pllim commented Nov 22, 2018

Just to be clear... 4.0.1?

@RonnyPfannschmidt
Copy link
Member Author

yes

# does not work the same in all platforms (see #4427)
# Path.absolute() exists, but it is not public (see https://bugs.python.org/issue25012)
convert=attr.converters.optional(
lambda p: Path(os.path.abspath(six.text_type(p)))

Choose a reason for hiding this comment

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

Brief note (was stalking IRC so I saw this comment) -- resolve() doesn't only resolve symlinks, but on windows it also resolves UNC paths from mounts (e.g. if you mount a network share at R:\\Some\\path but it really points at \\10.1.100.100\Some\path, Path.resolve() captures that but os.path.abspath() will return R:\\blah -- despite absolute not being public we typically handle this by trying resolve and falling back on absolute in pipenv at least

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @techalchemy for the note, that's interesting! 👍

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.

resolve manually set basetemp to a absolute path
4 participants