Merge pull request #4876 from nicoddemus/show-testpaths-in-header-4875
Show testpaths option in the header if it has been used for collection
This commit is contained in:
commit
35c85f0db9
|
@ -0,0 +1,5 @@
|
|||
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.
|
||||
|
||||
Also, ``inifile`` is only displayed if there's a configuration file, instead of an empty ``inifile:`` string.
|
|
@ -583,16 +583,21 @@ class TerminalReporter(object):
|
|||
self.write_line(line)
|
||||
|
||||
def pytest_report_header(self, config):
|
||||
inifile = ""
|
||||
line = "rootdir: %s" % config.rootdir
|
||||
|
||||
if config.inifile:
|
||||
inifile = " " + config.rootdir.bestrelpath(config.inifile)
|
||||
lines = ["rootdir: %s, inifile:%s" % (config.rootdir, inifile)]
|
||||
line += ", inifile: " + config.rootdir.bestrelpath(config.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))
|
||||
result = [line]
|
||||
|
||||
plugininfo = config.pluginmanager.list_plugin_distinfo()
|
||||
if plugininfo:
|
||||
|
||||
lines.append("plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
|
||||
return lines
|
||||
result.append("plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
|
||||
return result
|
||||
|
||||
def pytest_collection_finish(self, session):
|
||||
if self.config.getoption("collectonly"):
|
||||
|
|
|
@ -697,9 +697,9 @@ def test_invalid_options_show_extra_information(testdir):
|
|||
["-v", "dir2", "dir1"],
|
||||
],
|
||||
)
|
||||
def test_consider_args_after_options_for_rootdir_and_inifile(testdir, args):
|
||||
def test_consider_args_after_options_for_rootdir(testdir, args):
|
||||
"""
|
||||
Consider all arguments in the command-line for rootdir and inifile
|
||||
Consider all arguments in the command-line for rootdir
|
||||
discovery, even if they happen to occur after an option. #949
|
||||
"""
|
||||
# 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):
|
|||
args[i] = d2
|
||||
with root.as_cwd():
|
||||
result = testdir.runpytest(*args)
|
||||
result.stdout.fnmatch_lines(["*rootdir: *myroot, inifile:"])
|
||||
result.stdout.fnmatch_lines(["*rootdir: *myroot"])
|
||||
|
||||
|
||||
@pytest.mark.skipif("sys.platform == 'win32'")
|
||||
|
|
|
@ -332,7 +332,7 @@ def test_rootdir_option_arg(testdir, monkeypatch, path):
|
|||
result = testdir.runpytest("--rootdir={}".format(path))
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"*rootdir: {}/root, inifile:*".format(testdir.tmpdir),
|
||||
"*rootdir: {}/root".format(testdir.tmpdir),
|
||||
"root/test_rootdir_option_arg.py *",
|
||||
"*1 passed*",
|
||||
]
|
||||
|
|
|
@ -567,6 +567,35 @@ 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()
|
||||
|
||||
# no ini file
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["rootdir: *test_header0"])
|
||||
|
||||
# with inifile
|
||||
testdir.makeini("""[pytest]""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])
|
||||
|
||||
# with testpaths option, and not passing anything in the command-line
|
||||
testdir.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
testpaths = tests gui
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(
|
||||
["rootdir: *test_header0, inifile: tox.ini, testpaths: tests, gui"]
|
||||
)
|
||||
|
||||
# with testpaths option, passing directory in command-line: do not show testpaths then
|
||||
result = testdir.runpytest("tests")
|
||||
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])
|
||||
|
||||
def test_showlocals(self, testdir):
|
||||
p1 = testdir.makepyfile(
|
||||
"""
|
||||
|
@ -1199,15 +1228,6 @@ def test_summary_stats(exp_line, exp_color, stats_arg):
|
|||
assert color == exp_color
|
||||
|
||||
|
||||
def test_no_trailing_whitespace_after_inifile_word(testdir):
|
||||
result = testdir.runpytest("")
|
||||
assert "inifile:\n" in result.stdout.str()
|
||||
|
||||
testdir.makeini("[pytest]")
|
||||
result = testdir.runpytest("")
|
||||
assert "inifile: tox.ini\n" in result.stdout.str()
|
||||
|
||||
|
||||
class TestClassicOutputStyle(object):
|
||||
"""Ensure classic output style works as expected (#3883)"""
|
||||
|
||||
|
|
Loading…
Reference in New Issue