Skip to content

Commit 53a3d3e

Browse files
committed
Show testpaths option in the header if it has been used for collection
Fix pytest-dev#4875
1 parent e1f97e4 commit 53a3d3e

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

changelog/4875.feature.rst

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
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+
explicitly passed in the command line.

src/_pytest/terminal.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,13 @@ def pytest_report_header(self, config):
586586
inifile = ""
587587
if config.inifile:
588588
inifile = " " + config.rootdir.bestrelpath(config.inifile)
589-
lines = ["rootdir: %s, inifile:%s" % (config.rootdir, inifile)]
590589

590+
line = "rootdir: %s, inifile:%s" % (config.rootdir, inifile)
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+
lines = [line]
591596
plugininfo = config.pluginmanager.list_plugin_distinfo()
592597
if plugininfo:
593598

testing/test_terminal.py

+20
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,26 @@ 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+
result = testdir.runpytest()
574+
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile:"])
575+
576+
testdir.makeini(
577+
"""
578+
[pytest]
579+
testpaths = tests gui
580+
"""
581+
)
582+
result = testdir.runpytest()
583+
result.stdout.fnmatch_lines(
584+
["rootdir: *test_header0, inifile: tox.ini, testpaths: tests, gui"]
585+
)
586+
587+
result = testdir.runpytest("tests")
588+
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])
589+
570590
def test_showlocals(self, testdir):
571591
p1 = testdir.makepyfile(
572592
"""

0 commit comments

Comments
 (0)