Skip to content

Commit 19d13c0

Browse files
committed
Make --version write to stdout rather than stderr
Fix #8246
1 parent c9e9a59 commit 19d13c0

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

changelog/8246.breaking.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``--version`` now writes version information to ``stdout`` rather than ``stderr``.

src/_pytest/helpconfig.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ def unset_tracing() -> None:
127127

128128
def showversion(config: Config) -> None:
129129
if config.option.version > 1:
130-
sys.stderr.write(
130+
sys.stdout.write(
131131
"This is pytest version {}, imported from {}\n".format(
132132
pytest.__version__, pytest.__file__
133133
)
134134
)
135135
plugininfo = getpluginversioninfo(config)
136136
if plugininfo:
137137
for line in plugininfo:
138-
sys.stderr.write(line + "\n")
138+
sys.stdout.write(line + "\n")
139139
else:
140-
sys.stderr.write(f"pytest {pytest.__version__}\n")
140+
sys.stdout.write(f"pytest {pytest.__version__}\n")
141141

142142

143143
def pytest_cmdline_main(config: Config) -> Optional[Union[int, ExitCode]]:

testing/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ def pytest_addoption(parser):
17121712
assert result.ret == ExitCode.USAGE_ERROR
17131713

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

17181718

testing/test_helpconfig.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ def test_version_verbose(pytester: Pytester, pytestconfig, monkeypatch) -> None:
77
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
88
result = pytester.runpytest("--version", "--version")
99
assert result.ret == 0
10-
result.stderr.fnmatch_lines([f"*pytest*{pytest.__version__}*imported from*"])
10+
result.stdout.fnmatch_lines([f"*pytest*{pytest.__version__}*imported from*"])
1111
if pytestconfig.pluginmanager.list_plugin_distinfo():
12-
result.stderr.fnmatch_lines(["*setuptools registered plugins:", "*at*"])
12+
result.stdout.fnmatch_lines(["*setuptools registered plugins:", "*at*"])
1313

1414

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

2121

2222
def test_help(pytester: Pytester) -> None:

0 commit comments

Comments
 (0)