Show testpaths option in the header if it has been used for collection

Fix #4875
This commit is contained in:
Bruno Oliveira 2019-03-02 11:17:43 -03:00
parent e1f97e41e3
commit 53b8aa065c
3 changed files with 29 additions and 1 deletions

View File

@ -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.

View File

@ -586,8 +586,13 @@ class TerminalReporter(object):
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:

View File

@ -567,6 +567,26 @@ class TestTerminalFunctional(object):
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(
"""