Skip to content

Added support for less verbose version information #7169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Christian Tismer
Christoph Buelter
Christopher Dignam
Christopher Gilling
Claire Cecil
Claudio Madotto
CrazyMerlyn
Cyrus Maden
Expand Down
1 change: 1 addition & 0 deletions changelog/7128.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`pytest --version` now displays just the pytest version, while `pytest --version --version` displays more verbose information including plugins.
28 changes: 17 additions & 11 deletions src/_pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ def pytest_addoption(parser):
group.addoption(
"--version",
"-V",
action="store_true",
help="display pytest version and information about plugins.",
action="count",
default=0,
dest="version",
help="display pytest version and information about plugins."
"When given twice, also display information about plugins.",
)
group._addoption(
"-h",
Expand Down Expand Up @@ -116,19 +119,22 @@ def unset_tracing():


def showversion(config):
sys.stderr.write(
"This is pytest version {}, imported from {}\n".format(
pytest.__version__, pytest.__file__
if config.option.version > 1:
sys.stderr.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")
plugininfo = getpluginversioninfo(config)
if plugininfo:
for line in plugininfo:
sys.stderr.write(line + "\n")
else:
sys.stderr.write("pytest {}\n".format(pytest.__version__))


def pytest_cmdline_main(config):
if config.option.version:
if config.option.version > 0:
showversion(config)
return 0
elif config.option.help:
Expand Down
4 changes: 1 addition & 3 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,9 +1240,7 @@ def pytest_addoption(parser):
assert result.ret == ExitCode.USAGE_ERROR

result = testdir.runpytest("--version")
result.stderr.fnmatch_lines(
["*pytest*{}*imported from*".format(pytest.__version__)]
)
result.stderr.fnmatch_lines(["pytest {}".format(pytest.__version__)])
assert result.ret == ExitCode.USAGE_ERROR


Expand Down
13 changes: 10 additions & 3 deletions testing/test_helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
from _pytest.config import ExitCode


def test_version(testdir, pytestconfig):
def test_version_verbose(testdir, pytestconfig):
testdir.monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
result = testdir.runpytest("--version")
result = testdir.runpytest("--version", "--version")
assert result.ret == 0
# p = py.path.local(py.__file__).dirpath()
result.stderr.fnmatch_lines(
["*pytest*{}*imported from*".format(pytest.__version__)]
)
if pytestconfig.pluginmanager.list_plugin_distinfo():
result.stderr.fnmatch_lines(["*setuptools registered plugins:", "*at*"])


def test_version_less_verbose(testdir, pytestconfig):
testdir.monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
result = testdir.runpytest("--version")
assert result.ret == 0
# p = py.path.local(py.__file__).dirpath()
result.stderr.fnmatch_lines(["pytest {}".format(pytest.__version__)])


def test_help(testdir):
result = testdir.runpytest("--help")
assert result.ret == 0
Expand Down