Skip to content

Commit 79701c6

Browse files
authored
Added support for less verbose version information (#7169)
1 parent 05c22ff commit 79701c6

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Christian Tismer
6363
Christoph Buelter
6464
Christopher Dignam
6565
Christopher Gilling
66+
Claire Cecil
6667
Claudio Madotto
6768
CrazyMerlyn
6869
Cyrus Maden

changelog/7128.improvement.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`pytest --version` now displays just the pytest version, while `pytest --version --version` displays more verbose information including plugins.

src/_pytest/helpconfig.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ def pytest_addoption(parser):
4141
group.addoption(
4242
"--version",
4343
"-V",
44-
action="store_true",
45-
help="display pytest version and information about plugins.",
44+
action="count",
45+
default=0,
46+
dest="version",
47+
help="display pytest version and information about plugins."
48+
"When given twice, also display information about plugins.",
4649
)
4750
group._addoption(
4851
"-h",
@@ -116,19 +119,22 @@ def unset_tracing():
116119

117120

118121
def showversion(config):
119-
sys.stderr.write(
120-
"This is pytest version {}, imported from {}\n".format(
121-
pytest.__version__, pytest.__file__
122+
if config.option.version > 1:
123+
sys.stderr.write(
124+
"This is pytest version {}, imported from {}\n".format(
125+
pytest.__version__, pytest.__file__
126+
)
122127
)
123-
)
124-
plugininfo = getpluginversioninfo(config)
125-
if plugininfo:
126-
for line in plugininfo:
127-
sys.stderr.write(line + "\n")
128+
plugininfo = getpluginversioninfo(config)
129+
if plugininfo:
130+
for line in plugininfo:
131+
sys.stderr.write(line + "\n")
132+
else:
133+
sys.stderr.write("pytest {}\n".format(pytest.__version__))
128134

129135

130136
def pytest_cmdline_main(config):
131-
if config.option.version:
137+
if config.option.version > 0:
132138
showversion(config)
133139
return 0
134140
elif config.option.help:

testing/test_config.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,7 @@ def pytest_addoption(parser):
12431243
assert result.ret == ExitCode.USAGE_ERROR
12441244

12451245
result = testdir.runpytest("--version")
1246-
result.stderr.fnmatch_lines(
1247-
["*pytest*{}*imported from*".format(pytest.__version__)]
1248-
)
1246+
result.stderr.fnmatch_lines(["pytest {}".format(pytest.__version__)])
12491247
assert result.ret == ExitCode.USAGE_ERROR
12501248

12511249

testing/test_helpconfig.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22
from _pytest.config import ExitCode
33

44

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

1615

16+
def test_version_less_verbose(testdir, pytestconfig):
17+
testdir.monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD")
18+
result = testdir.runpytest("--version")
19+
assert result.ret == 0
20+
# p = py.path.local(py.__file__).dirpath()
21+
result.stderr.fnmatch_lines(["pytest {}".format(pytest.__version__)])
22+
23+
1724
def test_help(testdir):
1825
result = testdir.runpytest("--help")
1926
assert result.ret == 0

0 commit comments

Comments
 (0)