diff --git a/changelog/8246.breaking.rst b/changelog/8246.breaking.rst new file mode 100644 index 0000000000..ba9e5c8bee --- /dev/null +++ b/changelog/8246.breaking.rst @@ -0,0 +1 @@ +``--version`` now writes version information to ``stdout`` rather than ``stderr``. diff --git a/src/_pytest/helpconfig.py b/src/_pytest/helpconfig.py index b9360cecf6..78da45f0c3 100644 --- a/src/_pytest/helpconfig.py +++ b/src/_pytest/helpconfig.py @@ -127,7 +127,7 @@ 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__ ) @@ -135,9 +135,9 @@ def showversion(config: Config) -> None: 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]]: diff --git a/testing/test_config.py b/testing/test_config.py index 5dabb78124..1fdcea9bff 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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 diff --git a/testing/test_helpconfig.py b/testing/test_helpconfig.py index e2a27b4e70..dd77b55b5a 100644 --- a/testing/test_helpconfig.py +++ b/testing/test_helpconfig.py @@ -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():