Skip to content

Commit 68a341f

Browse files
Fix -V to show version information (#14382) (#14407)
This regressed in #13575. Fixes #14381. (cherry picked from commit d72943a) Co-authored-by: Bruno Oliveira <bruno@pytest.org>
1 parent 4afcd49 commit 68a341f

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

changelog/14381.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed ``-V`` (short form of ``--version``) to properly display the current version.

src/_pytest/config/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,12 @@ def main(
180180
181181
:returns: An exit code.
182182
"""
183-
# Handle a single `--version` argument early to avoid starting up the entire pytest infrastructure.
183+
# Handle a single `--version`/`-V` argument early to avoid starting up the entire pytest infrastructure.
184184
new_args = sys.argv[1:] if args is None else args
185-
if isinstance(new_args, Sequence) and new_args.count("--version") == 1:
185+
if (
186+
isinstance(new_args, Sequence)
187+
and (new_args.count("--version") + new_args.count("-V")) == 1
188+
):
186189
sys.stdout.write(f"pytest {__version__}\n")
187190
return ExitCode.OK
188191

testing/test_helpconfig.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ def test_version_verbose(pytester: Pytester, pytestconfig, monkeypatch) -> None:
1616
result.stdout.fnmatch_lines(["*registered third-party plugins:", "*at*"])
1717

1818

19-
def test_version_less_verbose(pytester: Pytester) -> None:
20-
"""Single ``--version`` parameter should display only the pytest version, without loading plugins (#13574)."""
19+
@pytest.mark.parametrize("flag", ["--version", "-V"])
20+
def test_version_less_verbose(pytester: Pytester, flag: str) -> None:
21+
"""Single ``--version`` or ``-V`` should display only the pytest version, without loading plugins (#13574)."""
2122
pytester.makeconftest("print('This should not be printed')")
22-
result = pytester.runpytest_subprocess("--version")
23+
result = pytester.runpytest_subprocess(flag)
2324
assert result.ret == ExitCode.OK
2425
assert result.stdout.str().strip() == f"pytest {pytest.__version__}"
2526

0 commit comments

Comments
 (0)