Skip to content

Commit

Permalink
Make --version write to stdout rather than stderr
Browse files Browse the repository at this point in the history
Fix #8246
  • Loading branch information
nicoddemus committed Jun 28, 2021
1 parent 2623ee2 commit 109312b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog/8246.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``--version`` now writes version information to ``stdout`` rather than ``stderr``.
6 changes: 3 additions & 3 deletions src/_pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ def unset_tracing() -> None:

def showversion(config: Config) -> None:
if config.option.version > 1:
sys.stderr.write(
sys.stdout.write(
"This is pytest version {}, imported from {}\n".format(
pytest.__version__, pytest.__file__
)
)
plugininfo = getpluginversioninfo(config)
if plugininfo:
for line in plugininfo:
sys.stderr.write(line + "\n")
sys.stdout.write(line + "\n")
else:
sys.stderr.write(f"pytest {pytest.__version__}\n")
sys.stdout.write(f"pytest {pytest.__version__}\n")


def pytest_cmdline_main(config: Config) -> Optional[Union[int, ExitCode]]:
Expand Down
2 changes: 1 addition & 1 deletion testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ def pytest_addoption(parser):
assert result.ret == ExitCode.USAGE_ERROR

result = pytester.runpytest("--version")
result.stderr.fnmatch_lines([f"pytest {pytest.__version__}"])
result.stdout.fnmatch_lines([f"pytest {pytest.__version__}"])
assert result.ret == ExitCode.USAGE_ERROR


Expand Down
6 changes: 3 additions & 3 deletions testing/test_helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ def test_version_verbose(pytester: Pytester, pytestconfig, monkeypatch) -> None:
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
result = pytester.runpytest("--version", "--version")
assert result.ret == 0
result.stderr.fnmatch_lines([f"*pytest*{pytest.__version__}*imported from*"])
result.stdout.fnmatch_lines([f"*pytest*{pytest.__version__}*imported from*"])
if pytestconfig.pluginmanager.list_plugin_distinfo():
result.stderr.fnmatch_lines(["*setuptools registered plugins:", "*at*"])
result.stdout.fnmatch_lines(["*setuptools registered plugins:", "*at*"])


def test_version_less_verbose(pytester: Pytester, pytestconfig, monkeypatch) -> None:
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
result = pytester.runpytest("--version")
assert result.ret == 0
result.stderr.fnmatch_lines([f"pytest {pytest.__version__}"])
result.stdout.fnmatch_lines([f"pytest {pytest.__version__}"])


def test_versions():
Expand Down

0 comments on commit 109312b

Please sign in to comment.