Skip to content

Commit

Permalink
Show testpaths option in the header if it has been used for collection
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Mar 2, 2019
1 parent e1f97e4 commit 53b8aa0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/4875.feature.rst
@@ -0,0 +1,3 @@
The `testpaths <https://docs.pytest.org/en/latest/reference.html#confval-testpaths>`__ configuration option is now displayed next
to the ``rootdir`` and ``inifile`` lines in the pytest header if the option is in effect, i.e., directories or file names were
not explicitly passed in the command line.
7 changes: 6 additions & 1 deletion src/_pytest/terminal.py
Expand Up @@ -586,8 +586,13 @@ def pytest_report_header(self, config):
inifile = ""
if config.inifile:
inifile = " " + config.rootdir.bestrelpath(config.inifile)
lines = ["rootdir: %s, inifile:%s" % (config.rootdir, inifile)]

line = "rootdir: %s, inifile:%s" % (config.rootdir, inifile)
testpaths = config.getini("testpaths")
if testpaths and config.args == testpaths:
rel_paths = [config.rootdir.bestrelpath(x) for x in testpaths]
line += ", testpaths: {}".format(", ".join(rel_paths))
lines = [line]
plugininfo = config.pluginmanager.list_plugin_distinfo()
if plugininfo:

Expand Down
20 changes: 20 additions & 0 deletions testing/test_terminal.py
Expand Up @@ -567,6 +567,26 @@ def test_passes():
if request.config.pluginmanager.list_plugin_distinfo():
result.stdout.fnmatch_lines(["plugins: *"])

def test_header(self, testdir, request):
testdir.tmpdir.join("tests").ensure_dir()
testdir.tmpdir.join("gui").ensure_dir()
result = testdir.runpytest()
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile:"])

testdir.makeini(
"""
[pytest]
testpaths = tests gui
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
["rootdir: *test_header0, inifile: tox.ini, testpaths: tests, gui"]
)

result = testdir.runpytest("tests")
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])

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

0 comments on commit 53b8aa0

Please sign in to comment.