Merge pull request #3756 from RonnyPfannschmidt/fix-3745

fix #3745 - display absolute cache_dir if necessary
This commit is contained in:
Bruno Oliveira 2018-08-01 07:09:19 -03:00 committed by GitHub
commit 4588130c1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

1
changelog/3745.bugfix Normal file
View File

@ -0,0 +1 @@
Display the absolute path if ``cache_dir`` is not relative to the ``rootdir`` instead of failing.

View File

@ -312,8 +312,15 @@ def cache(request):
def pytest_report_header(config): def pytest_report_header(config):
if config.option.verbose: if config.option.verbose:
relpath = config.cache._cachedir.relative_to(config.rootdir) cachedir = config.cache._cachedir
return "cachedir: {}".format(relpath) # TODO: evaluate generating upward relative paths
# starting with .., ../.. if sensible
try:
displaypath = cachedir.relative_to(config.rootdir)
except ValueError:
displaypath = cachedir
return "cachedir: {}".format(displaypath)
def cacheshow(config, session): def cacheshow(config, session):

View File

@ -150,6 +150,32 @@ def test_cache_reportheader(testdir):
result.stdout.fnmatch_lines(["cachedir: .pytest_cache"]) result.stdout.fnmatch_lines(["cachedir: .pytest_cache"])
def test_cache_reportheader_external_abspath(testdir, tmpdir_factory):
external_cache = tmpdir_factory.mktemp(
"test_cache_reportheader_external_abspath_abs"
)
testdir.makepyfile(
"""
def test_hello():
pass
"""
)
testdir.makeini(
"""
[pytest]
cache_dir = {abscache}
""".format(
abscache=external_cache
)
)
result = testdir.runpytest("-v")
result.stdout.fnmatch_lines(
["cachedir: {abscache}".format(abscache=external_cache)]
)
def test_cache_show(testdir): def test_cache_show(testdir):
result = testdir.runpytest("--cache-show") result = testdir.runpytest("--cache-show")
assert result.ret == 0 assert result.ret == 0