Skip to content

Commit 35c85f0

Browse files
authored
Merge pull request #4876 from nicoddemus/show-testpaths-in-header-4875
Show testpaths option in the header if it has been used for collection
2 parents e1f97e4 + 0deb7b1 commit 35c85f0

File tree

5 files changed

+49
-19
lines changed

5 files changed

+49
-19
lines changed

changelog/4875.feature.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The `testpaths <https://docs.pytest.org/en/latest/reference.html#confval-testpaths>`__ configuration option is now displayed next
2+
to the ``rootdir`` and ``inifile`` lines in the pytest header if the option is in effect, i.e., directories or file names were
3+
not explicitly passed in the command line.
4+
5+
Also, ``inifile`` is only displayed if there's a configuration file, instead of an empty ``inifile:`` string.

src/_pytest/terminal.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,21 @@ def _write_report_lines_from_hooks(self, lines):
583583
self.write_line(line)
584584

585585
def pytest_report_header(self, config):
586-
inifile = ""
586+
line = "rootdir: %s" % config.rootdir
587+
587588
if config.inifile:
588-
inifile = " " + config.rootdir.bestrelpath(config.inifile)
589-
lines = ["rootdir: %s, inifile:%s" % (config.rootdir, inifile)]
589+
line += ", inifile: " + config.rootdir.bestrelpath(config.inifile)
590+
591+
testpaths = config.getini("testpaths")
592+
if testpaths and config.args == testpaths:
593+
rel_paths = [config.rootdir.bestrelpath(x) for x in testpaths]
594+
line += ", testpaths: {}".format(", ".join(rel_paths))
595+
result = [line]
590596

591597
plugininfo = config.pluginmanager.list_plugin_distinfo()
592598
if plugininfo:
593-
594-
lines.append("plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
595-
return lines
599+
result.append("plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
600+
return result
596601

597602
def pytest_collection_finish(self, session):
598603
if self.config.getoption("collectonly"):

testing/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,9 @@ def test_invalid_options_show_extra_information(testdir):
697697
["-v", "dir2", "dir1"],
698698
],
699699
)
700-
def test_consider_args_after_options_for_rootdir_and_inifile(testdir, args):
700+
def test_consider_args_after_options_for_rootdir(testdir, args):
701701
"""
702-
Consider all arguments in the command-line for rootdir and inifile
702+
Consider all arguments in the command-line for rootdir
703703
discovery, even if they happen to occur after an option. #949
704704
"""
705705
# replace "dir1" and "dir2" from "args" into their real directory
@@ -713,7 +713,7 @@ def test_consider_args_after_options_for_rootdir_and_inifile(testdir, args):
713713
args[i] = d2
714714
with root.as_cwd():
715715
result = testdir.runpytest(*args)
716-
result.stdout.fnmatch_lines(["*rootdir: *myroot, inifile:"])
716+
result.stdout.fnmatch_lines(["*rootdir: *myroot"])
717717

718718

719719
@pytest.mark.skipif("sys.platform == 'win32'")

testing/test_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def test_one():
332332
result = testdir.runpytest("--rootdir={}".format(path))
333333
result.stdout.fnmatch_lines(
334334
[
335-
"*rootdir: {}/root, inifile:*".format(testdir.tmpdir),
335+
"*rootdir: {}/root".format(testdir.tmpdir),
336336
"root/test_rootdir_option_arg.py *",
337337
"*1 passed*",
338338
]

testing/test_terminal.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,35 @@ def test_passes():
567567
if request.config.pluginmanager.list_plugin_distinfo():
568568
result.stdout.fnmatch_lines(["plugins: *"])
569569

570+
def test_header(self, testdir, request):
571+
testdir.tmpdir.join("tests").ensure_dir()
572+
testdir.tmpdir.join("gui").ensure_dir()
573+
574+
# no ini file
575+
result = testdir.runpytest()
576+
result.stdout.fnmatch_lines(["rootdir: *test_header0"])
577+
578+
# with inifile
579+
testdir.makeini("""[pytest]""")
580+
result = testdir.runpytest()
581+
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])
582+
583+
# with testpaths option, and not passing anything in the command-line
584+
testdir.makeini(
585+
"""
586+
[pytest]
587+
testpaths = tests gui
588+
"""
589+
)
590+
result = testdir.runpytest()
591+
result.stdout.fnmatch_lines(
592+
["rootdir: *test_header0, inifile: tox.ini, testpaths: tests, gui"]
593+
)
594+
595+
# with testpaths option, passing directory in command-line: do not show testpaths then
596+
result = testdir.runpytest("tests")
597+
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])
598+
570599
def test_showlocals(self, testdir):
571600
p1 = testdir.makepyfile(
572601
"""
@@ -1199,15 +1228,6 @@ def test_summary_stats(exp_line, exp_color, stats_arg):
11991228
assert color == exp_color
12001229

12011230

1202-
def test_no_trailing_whitespace_after_inifile_word(testdir):
1203-
result = testdir.runpytest("")
1204-
assert "inifile:\n" in result.stdout.str()
1205-
1206-
testdir.makeini("[pytest]")
1207-
result = testdir.runpytest("")
1208-
assert "inifile: tox.ini\n" in result.stdout.str()
1209-
1210-
12111231
class TestClassicOutputStyle(object):
12121232
"""Ensure classic output style works as expected (#3883)"""
12131233

0 commit comments

Comments
 (0)