Added support for less verbose version information (#7169)
This commit is contained in:
parent
05c22ff823
commit
79701c65ed
1
AUTHORS
1
AUTHORS
|
@ -63,6 +63,7 @@ Christian Tismer
|
||||||
Christoph Buelter
|
Christoph Buelter
|
||||||
Christopher Dignam
|
Christopher Dignam
|
||||||
Christopher Gilling
|
Christopher Gilling
|
||||||
|
Claire Cecil
|
||||||
Claudio Madotto
|
Claudio Madotto
|
||||||
CrazyMerlyn
|
CrazyMerlyn
|
||||||
Cyrus Maden
|
Cyrus Maden
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
`pytest --version` now displays just the pytest version, while `pytest --version --version` displays more verbose information including plugins.
|
|
@ -41,8 +41,11 @@ def pytest_addoption(parser):
|
||||||
group.addoption(
|
group.addoption(
|
||||||
"--version",
|
"--version",
|
||||||
"-V",
|
"-V",
|
||||||
action="store_true",
|
action="count",
|
||||||
help="display pytest version and information about plugins.",
|
default=0,
|
||||||
|
dest="version",
|
||||||
|
help="display pytest version and information about plugins."
|
||||||
|
"When given twice, also display information about plugins.",
|
||||||
)
|
)
|
||||||
group._addoption(
|
group._addoption(
|
||||||
"-h",
|
"-h",
|
||||||
|
@ -116,19 +119,22 @@ def pytest_cmdline_parse():
|
||||||
|
|
||||||
|
|
||||||
def showversion(config):
|
def showversion(config):
|
||||||
sys.stderr.write(
|
if config.option.version > 1:
|
||||||
"This is pytest version {}, imported from {}\n".format(
|
sys.stderr.write(
|
||||||
pytest.__version__, pytest.__file__
|
"This is pytest version {}, imported from {}\n".format(
|
||||||
|
pytest.__version__, pytest.__file__
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
plugininfo = getpluginversioninfo(config)
|
||||||
plugininfo = getpluginversioninfo(config)
|
if plugininfo:
|
||||||
if plugininfo:
|
for line in plugininfo:
|
||||||
for line in plugininfo:
|
sys.stderr.write(line + "\n")
|
||||||
sys.stderr.write(line + "\n")
|
else:
|
||||||
|
sys.stderr.write("pytest {}\n".format(pytest.__version__))
|
||||||
|
|
||||||
|
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
if config.option.version:
|
if config.option.version > 0:
|
||||||
showversion(config)
|
showversion(config)
|
||||||
return 0
|
return 0
|
||||||
elif config.option.help:
|
elif config.option.help:
|
||||||
|
|
|
@ -1243,9 +1243,7 @@ def test_help_and_version_after_argument_error(testdir):
|
||||||
assert result.ret == ExitCode.USAGE_ERROR
|
assert result.ret == ExitCode.USAGE_ERROR
|
||||||
|
|
||||||
result = testdir.runpytest("--version")
|
result = testdir.runpytest("--version")
|
||||||
result.stderr.fnmatch_lines(
|
result.stderr.fnmatch_lines(["pytest {}".format(pytest.__version__)])
|
||||||
["*pytest*{}*imported from*".format(pytest.__version__)]
|
|
||||||
)
|
|
||||||
assert result.ret == ExitCode.USAGE_ERROR
|
assert result.ret == ExitCode.USAGE_ERROR
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,10 @@ import pytest
|
||||||
from _pytest.config import ExitCode
|
from _pytest.config import ExitCode
|
||||||
|
|
||||||
|
|
||||||
def test_version(testdir, pytestconfig):
|
def test_version_verbose(testdir, pytestconfig):
|
||||||
testdir.monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
|
testdir.monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
|
||||||
result = testdir.runpytest("--version")
|
result = testdir.runpytest("--version", "--version")
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
# p = py.path.local(py.__file__).dirpath()
|
|
||||||
result.stderr.fnmatch_lines(
|
result.stderr.fnmatch_lines(
|
||||||
["*pytest*{}*imported from*".format(pytest.__version__)]
|
["*pytest*{}*imported from*".format(pytest.__version__)]
|
||||||
)
|
)
|
||||||
|
@ -14,6 +13,14 @@ def test_version(testdir, pytestconfig):
|
||||||
result.stderr.fnmatch_lines(["*setuptools registered plugins:", "*at*"])
|
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):
|
def test_help(testdir):
|
||||||
result = testdir.runpytest("--help")
|
result = testdir.runpytest("--help")
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
|
|
Loading…
Reference in New Issue