diff --git a/changelog/4875.feature.rst b/changelog/4875.feature.rst index 6d91fb465..d9fb65ca5 100644 --- a/changelog/4875.feature.rst +++ b/changelog/4875.feature.rst @@ -1,3 +1,5 @@ The `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. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index fc78f4de4..0868bd751 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -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"): diff --git a/testing/test_config.py b/testing/test_config.py index c5c0ca939..3dd707bfa 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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'") diff --git a/testing/test_session.py b/testing/test_session.py index 6b185f76b..e5eb081d4 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -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*", ] diff --git a/testing/test_terminal.py b/testing/test_terminal.py index abe9549e2..fe67a6aec 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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)"""