Skip to content

Commit 0deb7b1

Browse files
committed
Do not show "inifile:" string if there's no configuration file
1 parent 53b8aa0 commit 0deb7b1

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

changelog/4875.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
The `testpaths <https://docs.pytest.org/en/latest/reference.html#confval-testpaths>`__ configuration option is now displayed next
22
to the ``rootdir`` and ``inifile`` lines in the pytest header if the option is in effect, i.e., directories or file names were
33
not explicitly passed in the command line.
4+
5+
Also, ``inifile`` is only displayed if there's a configuration file, instead of an empty ``inifile:`` string.

src/_pytest/terminal.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,21 +583,21 @@ def _write_report_lines_from_hooks(self, lines):
583583
self.write_line(line)
584584

585585
def pytest_report_header(self, config):
586-
inifile = ""
586+
line = "rootdir: %s" % config.rootdir
587+
587588
if config.inifile:
588-
inifile = " " + config.rootdir.bestrelpath(config.inifile)
589+
line += ", inifile: " + config.rootdir.bestrelpath(config.inifile)
589590

590-
line = "rootdir: %s, inifile:%s" % (config.rootdir, inifile)
591591
testpaths = config.getini("testpaths")
592592
if testpaths and config.args == testpaths:
593593
rel_paths = [config.rootdir.bestrelpath(x) for x in testpaths]
594594
line += ", testpaths: {}".format(", ".join(rel_paths))
595-
lines = [line]
595+
result = [line]
596+
596597
plugininfo = config.pluginmanager.list_plugin_distinfo()
597598
if plugininfo:
598-
599-
lines.append("plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
600-
return lines
599+
result.append("plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
600+
return result
601601

602602
def pytest_collection_finish(self, session):
603603
if self.config.getoption("collectonly"):

testing/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,9 @@ def test_invalid_options_show_extra_information(testdir):
697697
["-v", "dir2", "dir1"],
698698
],
699699
)
700-
def test_consider_args_after_options_for_rootdir_and_inifile(testdir, args):
700+
def test_consider_args_after_options_for_rootdir(testdir, args):
701701
"""
702-
Consider all arguments in the command-line for rootdir and inifile
702+
Consider all arguments in the command-line for rootdir
703703
discovery, even if they happen to occur after an option. #949
704704
"""
705705
# 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):
713713
args[i] = d2
714714
with root.as_cwd():
715715
result = testdir.runpytest(*args)
716-
result.stdout.fnmatch_lines(["*rootdir: *myroot, inifile:"])
716+
result.stdout.fnmatch_lines(["*rootdir: *myroot"])
717717

718718

719719
@pytest.mark.skipif("sys.platform == 'win32'")

testing/test_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def test_one():
332332
result = testdir.runpytest("--rootdir={}".format(path))
333333
result.stdout.fnmatch_lines(
334334
[
335-
"*rootdir: {}/root, inifile:*".format(testdir.tmpdir),
335+
"*rootdir: {}/root".format(testdir.tmpdir),
336336
"root/test_rootdir_option_arg.py *",
337337
"*1 passed*",
338338
]

testing/test_terminal.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,17 @@ def test_passes():
570570
def test_header(self, testdir, request):
571571
testdir.tmpdir.join("tests").ensure_dir()
572572
testdir.tmpdir.join("gui").ensure_dir()
573+
574+
# no ini file
575+
result = testdir.runpytest()
576+
result.stdout.fnmatch_lines(["rootdir: *test_header0"])
577+
578+
# with inifile
579+
testdir.makeini("""[pytest]""")
573580
result = testdir.runpytest()
574-
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile:"])
581+
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])
575582

583+
# with testpaths option, and not passing anything in the command-line
576584
testdir.makeini(
577585
"""
578586
[pytest]
@@ -584,6 +592,7 @@ def test_header(self, testdir, request):
584592
["rootdir: *test_header0, inifile: tox.ini, testpaths: tests, gui"]
585593
)
586594

595+
# with testpaths option, passing directory in command-line: do not show testpaths then
587596
result = testdir.runpytest("tests")
588597
result.stdout.fnmatch_lines(["rootdir: *test_header0, inifile: tox.ini"])
589598

@@ -1219,15 +1228,6 @@ def test_summary_stats(exp_line, exp_color, stats_arg):
12191228
assert color == exp_color
12201229

12211230

1222-
def test_no_trailing_whitespace_after_inifile_word(testdir):
1223-
result = testdir.runpytest("")
1224-
assert "inifile:\n" in result.stdout.str()
1225-
1226-
testdir.makeini("[pytest]")
1227-
result = testdir.runpytest("")
1228-
assert "inifile: tox.ini\n" in result.stdout.str()
1229-
1230-
12311231
class TestClassicOutputStyle(object):
12321232
"""Ensure classic output style works as expected (#3883)"""
12331233

0 commit comments

Comments
 (0)