Skip to content

Commit

Permalink
terminal: pytest_report_header: display cwd if != rootdir (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Mar 11, 2020
1 parent e6934d4 commit 7f601a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/_pytest/terminal.py
Expand Up @@ -732,13 +732,17 @@ def _write_report_lines_from_hooks(self, lines):
for line in collapse(lines):
self.write_line(line)

def pytest_report_header(self, config):
line = "rootdir: %s" % _shorten_path(Path(config.rootdir))
def pytest_report_header(self, config: Config) -> List[str]:
rootdir = _shorten_path(Path(str(config.rootdir)))
line = "rootdir: {}".format(rootdir)

if config.inifile:
line += ", inifile: {}".format(
_shorten_path(Path(config.rootdir.bestrelpath(config.inifile)))
_shorten_path(Path(config.rootdir.bestrelpath(config.inifile))) # type: ignore # (currently wrong)
)
cwd = _shorten_path(Path.cwd())
if rootdir != cwd:
line += ", cwd: {}".format(cwd)

testpaths = config.getini("testpaths")
if testpaths and config.args == testpaths:
Expand Down
5 changes: 2 additions & 3 deletions testing/test_session.py
Expand Up @@ -341,8 +341,7 @@ def test_rootdir_option_arg(testdir: Testdir, monkeypatch, path: str) -> None:
monkeypatch.setenv("PY_ROOTDIR_PATH", str(testdir.tmpdir))
path = path.format(relative=str(testdir.tmpdir), environment="$PY_ROOTDIR_PATH")

rootdir = testdir.mkdir("root")
rootdir.mkdir("tests")
testdir.mkdir("root")
testdir.makepyfile(
"""
import os
Expand All @@ -354,7 +353,7 @@ def test_one():
)

expected = [
"*rootdir: ~/root",
"*rootdir: ~/root, cwd: ~",
"test_rootdir_option_arg.py *",
"*1 passed*",
]
Expand Down
7 changes: 6 additions & 1 deletion testing/test_terminal.py
Expand Up @@ -663,7 +663,7 @@ def test_passes():
if request.config.pluginmanager.list_plugin_distinfo():
result.stdout.fnmatch_lines(["plugins: *"])

def test_header(self, testdir):
def test_header(self, testdir: Testdir) -> None:
testdir.tmpdir.join("tests").ensure_dir()
testdir.tmpdir.join("gui").ensure_dir()

Expand Down Expand Up @@ -692,6 +692,11 @@ def test_header(self, testdir):
result = testdir.runpytest("tests")
result.stdout.fnmatch_lines(["rootdir: ~, inifile: tox.ini"])

# Reports cwd if != rootdir.
testdir.makefile("ini", **{"tests/pytest": ""})
result = testdir.runpytest("tests")
result.stdout.fnmatch_lines(["rootdir: ~/tests, inifile: pytest.ini, cwd: ~"])

def test_showlocals(self, testdir):
p1 = testdir.makepyfile(
"""
Expand Down

0 comments on commit 7f601a9

Please sign in to comment.