fix #3745 - display absolute cache_dir if necessary

This commit is contained in:
Ronny Pfannschmidt 2018-08-01 08:25:37 +02:00
parent 253419316c
commit fcdc1d867e
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):
if config.option.verbose:
relpath = config.cache._cachedir.relative_to(config.rootdir)
return "cachedir: {}".format(relpath)
cachedir = config.cache._cachedir
# 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):

View File

@ -150,6 +150,32 @@ def test_cache_reportheader(testdir):
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):
result = testdir.runpytest("--cache-show")
assert result.ret == 0