Skip to content

Commit 04b3e5c

Browse files
committed
committing one last time before running checks again
1 parent 1270105 commit 04b3e5c

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def pytest_addoption(parser):
4343
"-V",
4444
action="count",
4545
default=0,
46+
dest="version",
4647
help="display pytest version and information about plugins."
4748
"When given twice, also display information about plugins.",
4849
)

testing/test_config.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,52 @@ def pytest_addoption(parser):
12441244
assert result.ret == ExitCode.USAGE_ERROR
12451245

12461246

1247+
def test_help_and_version_verbose_after_argument_error(testdir):
1248+
testdir.makeconftest(
1249+
"""
1250+
def validate(arg):
1251+
raise argparse.ArgumentTypeError("argerror")
1252+
1253+
def pytest_addoption(parser):
1254+
group = parser.getgroup('cov')
1255+
group.addoption(
1256+
"--invalid-option-should-allow-for-help",
1257+
type=validate,
1258+
)
1259+
"""
1260+
)
1261+
testdir.makeini(
1262+
"""
1263+
[pytest]
1264+
addopts = --invalid-option-should-allow-for-help
1265+
"""
1266+
)
1267+
result = testdir.runpytest("--help")
1268+
result.stdout.fnmatch_lines(
1269+
[
1270+
"usage: *",
1271+
"positional arguments:",
1272+
"NOTE: displaying only minimal help due to UsageError.",
1273+
]
1274+
)
1275+
result.stderr.fnmatch_lines(
1276+
[
1277+
"ERROR: usage: *",
1278+
"%s: error: argument --invalid-option-should-allow-for-help: expected one argument"
1279+
% (testdir.request.config._parser.optparser.prog,),
1280+
]
1281+
)
1282+
# Does not display full/default help.
1283+
assert "to see available markers type: pytest --markers" not in result.stdout.lines
1284+
assert result.ret == ExitCode.USAGE_ERROR
1285+
1286+
result = testdir.runpytest("--version", "--version")
1287+
result.stderr.fnmatch_lines(
1288+
["*pytest*{}*imported from*".format(pytest.__version__)]
1289+
)
1290+
assert result.ret == ExitCode.USAGE_ERROR
1291+
1292+
12471293
def test_help_formatter_uses_py_get_terminal_width(monkeypatch):
12481294
from _pytest.config.argparsing import DropShorterLongHelpFormatter
12491295

0 commit comments

Comments
 (0)