Merge pull request #7842 from bluetech/backport-7817

[6.1.x] terminal: fix crash in header reporting when absolute testpaths is used
This commit is contained in:
Ran Benita 2020-10-03 13:21:16 +03:00 committed by GitHub
commit 9df5267648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

View File

@ -0,0 +1 @@
Fixed crash in header reporting when :confval:`testpaths` is used and contains absolute paths (regression in 6.1.0).

View File

@ -718,10 +718,10 @@ class TerminalReporter:
if config.inipath:
line += ", configfile: " + bestrelpath(config.rootpath, config.inipath)
testpaths = config.getini("testpaths")
testpaths = config.getini("testpaths") # type: List[str]
if testpaths and config.args == testpaths:
rel_paths = [bestrelpath(config.rootpath, x) for x in testpaths]
line += ", testpaths: {}".format(", ".join(rel_paths))
line += ", testpaths: {}".format(", ".join(testpaths))
result = [line]
plugininfo = config.pluginmanager.list_plugin_distinfo()

View File

@ -18,6 +18,7 @@ import pytest
from _pytest._io.wcwidth import wcswidth
from _pytest.config import Config
from _pytest.config import ExitCode
from _pytest.monkeypatch import MonkeyPatch
from _pytest.pathlib import Path
from _pytest.pytester import Testdir
from _pytest.reports import BaseReport
@ -749,6 +750,29 @@ class TestTerminalFunctional:
result = testdir.runpytest("tests")
result.stdout.fnmatch_lines(["rootdir: *test_header0, configfile: tox.ini"])
def test_header_absolute_testpath(
self, testdir: Testdir, monkeypatch: MonkeyPatch
) -> None:
"""Regresstion test for #7814."""
tests = testdir.tmpdir.join("tests")
tests.ensure_dir()
testdir.makepyprojecttoml(
"""
[tool.pytest.ini_options]
testpaths = ['{}']
""".format(
tests
)
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
[
"rootdir: *absolute_testpath0, configfile: pyproject.toml, testpaths: {}".format(
tests
)
]
)
def test_no_header(self, testdir):
testdir.tmpdir.join("tests").ensure_dir()
testdir.tmpdir.join("gui").ensure_dir()