Do not show "inifile:" string if there's no configuration file
This commit is contained in:
parent
53b8aa065c
commit
0deb7b1696
|
@ -1,3 +1,5 @@
|
||||||
The `testpaths <https://docs.pytest.org/en/latest/reference.html#confval-testpaths>`__ configuration option is now displayed next
|
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
|
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.
|
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,21 +583,21 @@ class TerminalReporter(object):
|
||||||
self.write_line(line)
|
self.write_line(line)
|
||||||
|
|
||||||
def pytest_report_header(self, config):
|
def pytest_report_header(self, config):
|
||||||
inifile = ""
|
line = "rootdir: %s" % config.rootdir
|
||||||
if config.inifile:
|
|
||||||
inifile = " " + config.rootdir.bestrelpath(config.inifile)
|
if config.inifile:
|
||||||
|
line += ", inifile: " + config.rootdir.bestrelpath(config.inifile)
|
||||||
|
|
||||||
line = "rootdir: %s, inifile:%s" % (config.rootdir, inifile)
|
|
||||||
testpaths = config.getini("testpaths")
|
testpaths = config.getini("testpaths")
|
||||||
if testpaths and config.args == testpaths:
|
if testpaths and config.args == testpaths:
|
||||||
rel_paths = [config.rootdir.bestrelpath(x) for x in testpaths]
|
rel_paths = [config.rootdir.bestrelpath(x) for x in testpaths]
|
||||||
line += ", testpaths: {}".format(", ".join(rel_paths))
|
line += ", testpaths: {}".format(", ".join(rel_paths))
|
||||||
lines = [line]
|
result = [line]
|
||||||
|
|
||||||
plugininfo = config.pluginmanager.list_plugin_distinfo()
|
plugininfo = config.pluginmanager.list_plugin_distinfo()
|
||||||
if plugininfo:
|
if plugininfo:
|
||||||
|
result.append("plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
|
||||||
lines.append("plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
|
return result
|
||||||
return lines
|
|
||||||
|
|
||||||
def pytest_collection_finish(self, session):
|
def pytest_collection_finish(self, session):
|
||||||
if self.config.getoption("collectonly"):
|
if self.config.getoption("collectonly"):
|
||||||
|
|
|
@ -697,9 +697,9 @@ def test_invalid_options_show_extra_information(testdir):
|
||||||
["-v", "dir2", "dir1"],
|
["-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
|
discovery, even if they happen to occur after an option. #949
|
||||||
"""
|
"""
|
||||||
# replace "dir1" and "dir2" from "args" into their real directory
|
# 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
|
args[i] = d2
|
||||||
with root.as_cwd():
|
with root.as_cwd():
|
||||||
result = testdir.runpytest(*args)
|
result = testdir.runpytest(*args)
|
||||||
result.stdout.fnmatch_lines(["*rootdir: *myroot, inifile:"])
|
result.stdout.fnmatch_lines(["*rootdir: *myroot"])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif("sys.platform == 'win32'")
|
@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 = testdir.runpytest("--rootdir={}".format(path))
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"*rootdir: {}/root, inifile:*".format(testdir.tmpdir),
|
"*rootdir: {}/root".format(testdir.tmpdir),
|
||||||
"root/test_rootdir_option_arg.py *",
|
"root/test_rootdir_option_arg.py *",
|
||||||
"*1 passed*",
|
"*1 passed*",
|
||||||
]
|
]
|
||||||
|
|
|
@ -570,9 +570,17 @@ class TestTerminalFunctional(object):
|
||||||
def test_header(self, testdir, request):
|
def test_header(self, testdir, request):
|
||||||
testdir.tmpdir.join("tests").ensure_dir()
|
testdir.tmpdir.join("tests").ensure_dir()
|
||||||
testdir.tmpdir.join("gui").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(
|
testdir.makeini(
|
||||||
"""
|
"""
|
||||||
[pytest]
|
[pytest]
|
||||||
|
@ -584,6 +592,7 @@ class TestTerminalFunctional(object):
|
||||||
["rootdir: *test_header0, inifile: tox.ini, testpaths: tests, gui"]
|
["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 = testdir.runpytest("tests")
|
||||||
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])
|
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
|
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):
|
class TestClassicOutputStyle(object):
|
||||||
"""Ensure classic output style works as expected (#3883)"""
|
"""Ensure classic output style works as expected (#3883)"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue