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

terminal: fix crash in header reporting when testpaths is used without cli arguments #7816

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/7814.bugfix.rst
@@ -0,0 +1 @@
Fixed crash in header reporting when :confval:`testpaths` is used without CLI arguments (regression in 6.1.0).
6 changes: 4 additions & 2 deletions src/_pytest/terminal.py
Expand Up @@ -718,9 +718,11 @@ def pytest_report_header(self, config: Config) -> List[str]:
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]
rel_paths = [
bestrelpath(config.rootpath, Path(absolutepath(x))) for x in testpaths
]
line += ", testpaths: {}".format(", ".join(rel_paths))
result = [line]

Expand Down
19 changes: 19 additions & 0 deletions testing/test_terminal.py
Expand Up @@ -18,6 +18,7 @@
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
Expand Down Expand Up @@ -749,6 +750,24 @@ def test_header(self, testdir):
result = testdir.runpytest("tests")
result.stdout.fnmatch_lines(["rootdir: *test_header0, configfile: tox.ini"])

def test_header_testpaths_are_relative(
self, testdir: Testdir, monkeypatch: MonkeyPatch
) -> None:
"""Regresstion test for #7814."""
testdir.tmpdir.join("tests").ensure_dir()
testdir.makeini(
"""
[pytest]
testpaths = {}/tests
""".format(
testdir.tmpdir
)
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
["rootdir: *are_relative0, configfile: tox.ini, testpaths: tests"]
)

def test_no_header(self, testdir):
testdir.tmpdir.join("tests").ensure_dir()
testdir.tmpdir.join("gui").ensure_dir()
Expand Down