Show package version number on kanta CLI

This commit is contained in:
2026-09-12 22:15:17 +00:00
parent 2e6f48bac5
commit 8e780d7ee4
2 changed files with 37 additions and 1 deletions
+19
View File
@@ -3,6 +3,8 @@
import sys
from datetime import UTC, datetime
import pytest
from kanta.__main__ import (
_extra_import_paths,
_format_ts,
@@ -131,6 +133,23 @@ def test_cli_strips_ansi_without_color_support(tmp_path, capsys, monkeypatch):
assert "snapshot s0" in err
def test_cli_version_on_help_and_version_flag(capsys):
"""--help and --version print the installed package version."""
import importlib.metadata
version = importlib.metadata.version("kanta")
with pytest.raises(SystemExit) as help_exit:
main(["--help"])
assert help_exit.value.code == 0
assert f"kanta {version}" in capsys.readouterr().out
with pytest.raises(SystemExit) as version_exit:
main(["--version"])
assert version_exit.value.code == 0
assert capsys.readouterr().out.strip() == f"kanta {version}"
def test_import_dotted_from_file_path(tmp_path):
"""--data can be a filesystem path with an optional colon-separated symbol."""
module = tmp_path / "models.py"