Do not show "inifile:" string if there's no configuration file

This commit is contained in:
Bruno Oliveira 2019-03-02 11:31:09 -03:00
parent 53b8aa065c
commit 0deb7b1696
5 changed files with 25 additions and 23 deletions

View File

@ -1,3 +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.

View File

@ -583,21 +583,21 @@ class TerminalReporter(object):
self.write_line(line)
def pytest_report_header(self, config):
inifile = ""
if config.inifile:
inifile = " " + config.rootdir.bestrelpath(config.inifile)
line = "rootdir: %s" % config.rootdir
if config.inifile:
line += ", inifile: " + config.rootdir.bestrelpath(config.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]
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"):

View File

@ -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'")

View File

@ -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*",
]

View File

@ -570,9 +570,17 @@ class TestTerminalFunctional(object):
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:"])
# 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]
@ -584,6 +592,7 @@ class TestTerminalFunctional(object):
["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"])
@ -1219,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)"""