diff --git a/AGENTS.md b/AGENTS.md
index 1a19d5306..53b74a229 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -33,6 +33,10 @@ A comment says what the code does and why, in one or two sentences. Change histo
Framework code raises a `VipError` subclass (`src/vip/errors.py`) instead of calling `sys.exit`. `src/vip/cli/app.py`'s `except VipError` handler is the single top-level place that maps an error to a process exit code. Test steps and assertions under `src/vip_tests/` don't catch `VipError`; if a client call raises one, let it propagate so the test fails with the real cause instead of a laundered message (see docs/test-architecture.md's "Fail, warn, or skip" section). The exception is best-effort teardown: the end-of-run Connect sweep in `src/vip_tests/conftest.py` catches `ProductUnreachableError` and logs it, so a failed cleanup can't turn a green run red. A broad `except Exception` is allowed only where an exception is genuinely tolerated (not translated into a more specific error and re-raised) -- mark it `# noqa: BLE001` and add a comment naming what is being tolerated and why, the way `src/vip/workbench_ui.py` does at each of its blind excepts.
+## Output
+
+Never call `print()` (ruff `T201` enforces it); write through `src/vip/output.py`. `out()` is for command results a caller might pipe (report path, install plan, status table, JSON, version) and goes to stdout; `info()` (progress), `warn()`, `error()` and `debug()` (diagnostics) go to stderr. Pass the message exactly as it should appear: the module adds no prefix, so `>>> ` stays in the caller's string. The level is `quiet` (hides `info`), `normal`, or `verbose` (adds `debug`); `vip -q` / `vip -v` set it before the subcommand runs (`vip verify --verbose` still means full tracebacks and also enables `debug`, unless `-q` is given, which always wins). `VIP_VERBOSITY=quiet|normal|verbose` carries the level into the pytest subprocess that `vip verify` starts, so code under `vip.auth` and `vip.plugin` honours it, and the `vip_verbose` fixture is `False` under quiet even with `--vip-verbose`. `vip.*` `logging` records reach stderr through `output.configure_logging()`, which the CLI entry point calls once and `plugin/configure.py::pytest_configure` calls with `propagate=True` in the pytest subprocess and each xdist worker, so pytest's log capture still sees them. Selftests assert on `capsys.readouterr().out` or `.err` to match the stream; a test that needs `debug` output calls `set_verbosity(Verbosity.VERBOSE)`.
+
## Testing
There are two distinct test suites:
diff --git a/docs/development.md b/docs/development.md
index 10a53bf67..a1f87edf8 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -43,7 +43,9 @@ uv run --extra dev ruff format . # reformat
```
Ruff's rule set is the `select` list in `pyproject.toml` under
-`[tool.ruff.lint]`; line length is 100.
+`[tool.ruff.lint]`; line length is 100. The set includes `T201`, so `print()` is a
+lint error: write through `vip.output` instead (`out()` for stdout results,
+`info()`/`warn()`/`error()`/`debug()` for stderr; see "Output" in `AGENTS.md`).
### Pre-commit hooks (optional)
diff --git a/pyproject.toml b/pyproject.toml
index 32a182df2..efd0ef826 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -252,7 +252,7 @@ src = ["src", "selftests", "examples"]
# PLW1514 is preview-only; explicit-preview-rules keeps every other preview rule off.
preview = true
explicit-preview-rules = true
-select = ["ARG001", "ARG002", "ARG005", "B", "BLE", "C4", "D101", "D102", "D103", "D202", "D209", "D210", "D403", "D413", "E", "F", "I", "ISC", "N", "PERF", "PGH", "PIE", "PLC0207", "PLC0415", "PLR0124", "PLR0402", "PLR1711", "PLR5501", "PLW0108", "PLW1510", "PLW1514", "PT", "PTH", "RET", "RUF001", "RUF002", "RUF003", "RUF012", "RUF023", "RUF043", "RUF059", "RUF100", "S101", "SIM", "TID", "UP"]
+select = ["ARG001", "ARG002", "ARG005", "B", "BLE", "C4", "D101", "D102", "D103", "D202", "D209", "D210", "D403", "D413", "E", "F", "I", "ISC", "N", "PERF", "PGH", "PIE", "PLC0207", "PLC0415", "PLR0124", "PLR0402", "PLR1711", "PLR5501", "PLW0108", "PLW1510", "PLW1514", "PT", "PTH", "RET", "RUF001", "RUF002", "RUF003", "RUF012", "RUF023", "RUF043", "RUF059", "RUF100", "S101", "SIM", "T201", "TID", "UP"]
# PERF203: per-item try/except in cleanup and probe loops is deliberate (the loop must continue past a failing item), and the per-iteration cost it flags is gone on Python 3.11+.
ignore = [
@@ -265,4 +265,6 @@ ignore = [
"selftests/**" = ["ARG001", "ARG002", "ARG005", "D101", "D102", "D103", "PLC0415", "S101"]
"src/vip_tests/**" = ["ARG001", "ARG002", "ARG005", "D101", "D102", "D103", "PLC0415", "S101"]
"examples/**" = ["ARG001", "ARG002", "ARG005", "D101", "D102", "D103", "S101"]
-"docker/**" = ["ARG001", "ARG002", "ARG005", "S101"]
+# T201: standalone scripts that cannot import vip.output; their stdout is read by CI and shell callers.
+"docker/**" = ["ARG001", "ARG002", "ARG005", "S101", "T201"]
+"scripts/**" = ["T201"]
diff --git a/selftests/conftest.py b/selftests/conftest.py
index 38769a04d..90723dfbf 100644
--- a/selftests/conftest.py
+++ b/selftests/conftest.py
@@ -7,10 +7,13 @@
from __future__ import annotations
+import logging
from pathlib import Path
import pytest
+from vip import output
+
# Enable the pytester fixture for plugin integration tests.
pytest_plugins = ["pytester"]
@@ -26,6 +29,19 @@
)
+@pytest.fixture(autouse=True)
+def _restore_output_state():
+ """Undo verbosity and ``vip`` logger changes a selftest (or ``main()``) made."""
+ level = output.get_verbosity()
+ logger = logging.getLogger("vip")
+ handlers, propagate, log_level = list(logger.handlers), logger.propagate, logger.level
+ yield
+ output.set_verbosity(level)
+ logger.handlers[:] = handlers
+ logger.propagate = propagate
+ logger.setLevel(log_level)
+
+
@pytest.fixture(autouse=True)
def _restore_auth_entrypoints():
"""Undo in-process ``pytester`` runs that rebind ``vip.auth``'s entrypoints.
diff --git a/selftests/install/test_playwright.py b/selftests/install/test_playwright.py
index 73041b228..5e5b625db 100644
--- a/selftests/install/test_playwright.py
+++ b/selftests/install/test_playwright.py
@@ -194,7 +194,7 @@ def test_install_chromium_filters_beware_preamble_and_replaces(monkeypatch, caps
assert "officially supported" not in out.out + out.err
assert "downloading fallback build" not in out.out + out.err
assert "Downloading Chromium 120" in out.out
- assert "Installed Playwright Chromium" in out.out
+ assert "Installed Playwright Chromium" in out.err
def test_install_chromium_forwards_normal_output_unchanged(monkeypatch, capsys):
@@ -208,4 +208,4 @@ def test_install_chromium_forwards_normal_output_unchanged(monkeypatch, capsys):
assert "Downloading Chromium 120" in out.out
assert "Chromium downloaded." in out.out
# No BEWARE means no vip summary line either.
- assert "Installed Playwright Chromium" not in out.out
+ assert "Installed Playwright Chromium" not in out.out + out.err
diff --git a/selftests/install/test_runner.py b/selftests/install/test_runner.py
index c274520be..4a5969798 100644
--- a/selftests/install/test_runner.py
+++ b/selftests/install/test_runner.py
@@ -127,7 +127,7 @@ def test_execute_install_plan_not_root_message_names_skip_system(monkeypatch, tm
rc = rn.execute_install_plan(plan, manifest=manifest, manifest_path=manifest_path)
assert rc == 2
- assert "--skip-system" in capsys.readouterr().out
+ assert "--skip-system" in capsys.readouterr().err
def test_execute_install_plan_claims_pending(monkeypatch, tmp_path: Path):
diff --git a/selftests/test_auth_apikey.py b/selftests/test_auth_apikey.py
index 252b8c6d8..a06d7ff10 100644
--- a/selftests/test_auth_apikey.py
+++ b/selftests/test_auth_apikey.py
@@ -567,7 +567,7 @@ def get_side_effect(path, **_kw):
with patcher:
assert _create_api_key_via_session(page, "https://c.example.com", "k") is None
- assert "boom" in capsys.readouterr().out
+ assert "boom" in capsys.readouterr().err
def test_user_endpoint_403_warning_includes_body(self, capsys):
"""When cookie auth is rejected at /v1/user, the response body must
@@ -588,7 +588,7 @@ def test_user_endpoint_403_warning_includes_body(self, capsys):
with patcher:
assert _create_api_key_via_session(page, "https://c.example.com", "k") is None
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "HTTP 403" in out
assert "CSRF token is required" in out
@@ -622,7 +622,7 @@ def get_side_effect(path, **_kw):
result = _create_api_key_via_session(page, "https://c.example.com/connect", "k")
assert result is None
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
# Full URL is reported, not just the relative path.
assert "https://c.example.com/connect/__api__/v1/user" in out
# Content-Type appears so users can spot Go-default vs Connect 404s.
@@ -658,7 +658,7 @@ def get_side_effect(path, **_kw):
assert "/v1/user" in calls
assert "/server_settings" in calls
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "/server_settings returned HTTP 404" in out
assert "wrong path prefix" in out
assert "https://c.example.com/connect" in out
@@ -690,7 +690,7 @@ def get_side_effect(path, **_kw):
with patcher:
_create_api_key_via_session(page, "https://c.example.com", "k")
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "/server_settings returned HTTP 200" in out
assert "wrong path prefix" not in out
@@ -722,7 +722,7 @@ def get_side_effect(path, **_kw):
result = _create_api_key_via_session(page, "https://c.example.com", "k")
assert result is None
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "/server_settings probe failed" in out
assert "probe timed out" in out
@@ -747,7 +747,7 @@ def raise_connect_error(*_a, **_kw):
with patcher:
assert _create_api_key_via_session(page, "https://c.example.com", "k") is None
- assert "simulated TLS rejection" in capsys.readouterr().out
+ assert "simulated TLS rejection" in capsys.readouterr().err
def test_missing_xsrf_cookie_still_runs(self):
"""With no RSC-XSRF cookie the call still runs; no X-Rsc-Xsrf header sent."""
diff --git a/selftests/test_auth_cache.py b/selftests/test_auth_cache.py
index f121e09ce..31c246448 100644
--- a/selftests/test_auth_cache.py
+++ b/selftests/test_auth_cache.py
@@ -67,7 +67,7 @@ def test_unwritable_cache_root_skips_caching_without_raising(
finally:
locked.chmod(0o700)
- assert "Skipping auth cache" in capsys.readouterr().out
+ assert "Skipping auth cache" in capsys.readouterr().err
assert not list(work.glob(".vip-auth-cache*"))
def test_skips_cache_when_connect_configured_but_mint_failed(self, tmp_path):
@@ -172,7 +172,7 @@ def test_unserialisable_meta_leaves_no_cache(self, tmp_path, capsys):
assert not cache.exists()
assert not cache.with_suffix(".meta.json").exists()
- assert "Skipping auth cache" in capsys.readouterr().out
+ assert "Skipping auth cache" in capsys.readouterr().err
@pytest.mark.skipif(sys.platform == "win32", reason="POSIX permission bits")
def test_tightens_an_existing_cache_directory(self, tmp_path):
@@ -317,7 +317,7 @@ def test_rejects_cache_when_connect_url_differs(self, tmp_path, capsys):
)
assert session is None
- assert "Ignoring cached auth session" in capsys.readouterr().out
+ assert "Ignoring cached auth session" in capsys.readouterr().err
def test_rejects_cache_when_workbench_was_not_recorded(self, tmp_path):
"""A cache minted with only Connect lacks Workbench cookies; a
@@ -632,7 +632,7 @@ def test_dead_workbench_session_is_a_cache_miss(self, tmp_path, capsys, monkeypa
)
assert session is None
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "Ignoring cached auth session" in out
assert "no longer authenticates Workbench" in out
@@ -843,7 +843,8 @@ def test_resolving_moves_nothing_and_prints_nothing(self, tmp_path, monkeypatch,
auth_cache_path()
assert len(list(tmp_path.glob(".vip-auth-cache*"))) == 2
- assert capsys.readouterr().out == ""
+ captured = capsys.readouterr()
+ assert (captured.out, captured.err) == ("", "")
def test_resolving_creates_nothing_without_a_legacy_cache(self, tmp_path, monkeypatch):
from vip.auth import auth_cache_path
@@ -874,7 +875,7 @@ def test_no_home_directory_skips_the_cache(self, tmp_path, monkeypatch, capsys):
assert prepare_auth_cache() is None
- assert "Skipping auth cache" in capsys.readouterr().out
+ assert "Skipping auth cache" in capsys.readouterr().err
assert set(tmp_path.iterdir()) == before
def test_no_home_directory_leaves_legacy_cache_alone(self, tmp_path, monkeypatch):
@@ -1499,7 +1500,7 @@ def test_cache_miss_message_quotes_the_detail(self, tmp_path, capsys, monkeypatc
cache, requested_connect_url=None, requested_workbench_url="https://w.example.com"
)
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "Workbench answered 401 Unauthorized" in out
assert "sent back to the sign-in page" not in out
diff --git a/selftests/test_auth_headless.py b/selftests/test_auth_headless.py
index 18eb4f63d..844fb46ee 100644
--- a/selftests/test_auth_headless.py
+++ b/selftests/test_auth_headless.py
@@ -10,6 +10,7 @@
AuthConfigError,
start_headless_auth,
)
+from vip.output import Verbosity, get_verbosity, set_verbosity
class TestStartHeadlessAuthValidation:
@@ -34,6 +35,19 @@ def test_no_urls_raises_without_cache(self):
with pytest.raises(AuthConfigError, match="at least one product URL"):
start_headless_auth()
+ def test_verbose_flag_does_not_override_quiet(self):
+ """``vip -q verify --headless-auth --verbose`` must stay quiet."""
+ set_verbosity(Verbosity.QUIET)
+ with pytest.raises(AuthConfigError):
+ start_headless_auth(verbose=True)
+ assert get_verbosity() is Verbosity.QUIET
+
+ def test_verbose_flag_raises_normal_to_verbose(self):
+ set_verbosity(Verbosity.NORMAL)
+ with pytest.raises(AuthConfigError):
+ start_headless_auth(verbose=True)
+ assert get_verbosity() is Verbosity.VERBOSE
+
def test_invalid_totp_seed_raises_before_playwright(self, monkeypatch):
"""Bad VIP_TEST_TOTP_SECRET fails fast with a clear error."""
monkeypatch.setenv("VIP_TEST_TOTP_SECRET", "not-valid-base32-!!!")
diff --git a/selftests/test_auth_interactive.py b/selftests/test_auth_interactive.py
index 25815d930..f2e670a05 100644
--- a/selftests/test_auth_interactive.py
+++ b/selftests/test_auth_interactive.py
@@ -471,7 +471,7 @@ def test_playwright_error_on_goto_is_non_fatal(self, capsys):
result = _authenticate_workbench(page, "https://wb.example.com/pwb")
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "Could not reach Workbench" in out
assert "https://wb.example.com/pwb" in out
assert result is not None
diff --git a/selftests/test_auth_scheme.py b/selftests/test_auth_scheme.py
index 1f3cd3736..516af140e 100644
--- a/selftests/test_auth_scheme.py
+++ b/selftests/test_auth_scheme.py
@@ -267,7 +267,7 @@ def test_fallback_is_logged_loudly(self, capsys):
with patch("httpx.get", side_effect=httpx.ConnectError("nope")):
resolve_url_scheme(pc)
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "connect.example.com" in out
assert "http://connect.example.com" in out
@@ -280,7 +280,8 @@ def test_success_is_not_logged(self, capsys):
with patch("httpx.get", return_value=MagicMock(status_code=200)):
resolve_url_scheme(pc)
- assert capsys.readouterr().out == ""
+ captured = capsys.readouterr()
+ assert (captured.out, captured.err) == ("", "")
def test_mutates_pc_in_place_and_resets_inferred_flag(self):
"""After resolving, pc.url holds the final value and
@@ -386,7 +387,7 @@ def test_tls_present_but_untrusted_names_the_remedy(self, capsys):
):
resolve_url_scheme(pc)
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "NOT falling back to plaintext" in out
assert "insecure" in out
assert "ca_bundle" in out
diff --git a/selftests/test_cli_cleanup.py b/selftests/test_cli_cleanup.py
index acf12c112..e5ae4c8d5 100644
--- a/selftests/test_cli_cleanup.py
+++ b/selftests/test_cli_cleanup.py
@@ -130,7 +130,7 @@ def _fail(*a, **k):
vip.cli.run_cleanup(_make_args(connect_url="https://c.example.com"))
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "Deleted 3 VIP test content item(s)" in out
assert "Cleanup completed successfully" in out
@@ -211,7 +211,7 @@ def cleanup_vip_content(self):
_make_args(connect_url="https://c.example.com", workbench_url="https://wb.example.com")
)
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "Deleted 1 VIP test content item(s)" in out
assert called["url"] == "https://wb.example.com"
@@ -687,7 +687,7 @@ def test_clean_token_sweep_skips_browser_auth(self, monkeypatch, capsys):
assert fake.swept_users == ["alice"]
assert fake.init_kwargs["api_key"] == "tok"
assert fake.closed
- assert "Quit 2 VIP Workbench session(s) via the API token" in capsys.readouterr().out
+ assert "Quit 2 VIP Workbench session(s) via the API token" in capsys.readouterr().err
def test_token_without_a_username_does_not_use_the_token_path(self, monkeypatch):
monkeypatch.setattr(
@@ -727,7 +727,7 @@ def _headless(**kwargs):
)
assert reached == {"headless": True}
- assert "falling back to browser sign-in" in capsys.readouterr().out
+ assert "falling back to browser sign-in" in capsys.readouterr().err
def test_survivors_fall_back_to_browser_auth(self, monkeypatch):
fake = _FakeTokenWorkbenchClient(remaining=[{"id": "a1", "label": "VIP x - main-1"}])
diff --git a/selftests/test_cli_url_scheme.py b/selftests/test_cli_url_scheme.py
index 46fbd9c51..78f239614 100644
--- a/selftests/test_cli_url_scheme.py
+++ b/selftests/test_cli_url_scheme.py
@@ -137,7 +137,7 @@ def _record_init(self, *a, **k):
vip.cli.run_cleanup(self._args(connect_url="connect.example.com"))
assert constructed == ["http://connect.example.com"]
- assert "http://connect.example.com" in capsys.readouterr().out
+ assert "http://connect.example.com" in capsys.readouterr().err
def test_explicit_scheme_connect_url_never_probes(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
diff --git a/selftests/test_cli_verbosity.py b/selftests/test_cli_verbosity.py
new file mode 100644
index 000000000..06ce6b83c
--- /dev/null
+++ b/selftests/test_cli_verbosity.py
@@ -0,0 +1,66 @@
+"""Tests for the root ``-q/--quiet`` and ``-v/--verbose`` flags and their plumbing."""
+
+from __future__ import annotations
+
+import logging
+import sys
+from unittest.mock import patch
+
+import pytest
+
+from vip import output
+from vip.cli import main
+from vip.output import Verbosity
+
+
+@pytest.mark.parametrize(
+ ("argv", "expected"),
+ [
+ (["version"], Verbosity.NORMAL),
+ (["-q", "version"], Verbosity.QUIET),
+ (["--quiet", "version"], Verbosity.QUIET),
+ (["-v", "version"], Verbosity.VERBOSE),
+ (["--verbose", "version"], Verbosity.VERBOSE),
+ ],
+)
+def test_root_flags_set_verbosity(monkeypatch, argv, expected):
+ monkeypatch.delenv(output.VERBOSITY_ENV_VAR, raising=False)
+ output.set_verbosity(Verbosity.NORMAL)
+ monkeypatch.setattr(sys, "argv", ["vip", *argv])
+ with patch("vip.cli.app.run_version"):
+ main()
+ assert output.get_verbosity() is expected
+
+
+def test_quiet_and_verbose_are_mutually_exclusive(monkeypatch, capsys):
+ monkeypatch.setattr(sys, "argv", ["vip", "-q", "-v", "version"])
+ with pytest.raises(SystemExit) as exc_info:
+ main()
+ assert exc_info.value.code == 2
+ assert "not allowed with argument" in capsys.readouterr().err
+
+
+def test_main_attaches_log_handler(monkeypatch):
+ monkeypatch.setattr(sys, "argv", ["vip", "version"])
+ logger = logging.getLogger("vip")
+ logger.handlers.clear()
+ with patch("vip.cli.app.run_version"):
+ main()
+ assert any(isinstance(h, output._StderrHandler) for h in logger.handlers)
+
+
+def test_verify_verbose_keeps_its_own_dest_and_enables_debug(monkeypatch, tmp_path):
+ """``vip verify --verbose`` still means tracebacks, and now also debug output."""
+ cfg = tmp_path / "vip.toml"
+ cfg.write_text("[general]\n", encoding="utf-8")
+ captured: dict = {}
+
+ def fake_run_verify(args):
+ captured["verbose"] = args.verbose
+ captured["output_verbose"] = args.output_verbose
+
+ monkeypatch.setattr(sys, "argv", ["vip", "verify", "--verbose", "--config", str(cfg)])
+ with patch("vip.cli.app.run_verify", fake_run_verify):
+ main()
+ assert captured == {"verbose": True, "output_verbose": False}
+ assert output.get_verbosity() is Verbosity.VERBOSE
diff --git a/selftests/test_cli_verify.py b/selftests/test_cli_verify.py
index dda71c5ff..cec5ce1d6 100644
--- a/selftests/test_cli_verify.py
+++ b/selftests/test_cli_verify.py
@@ -13,6 +13,7 @@
import pytest
from vip.cli import DEFAULT_TEST_TIMEOUT_SECONDS
+from vip.output import VERBOSITY_ENV_VAR, Verbosity, set_verbosity
def _make_args(**overrides) -> argparse.Namespace:
@@ -167,7 +168,7 @@ def test_disabled_product_says_disabled(self, tmp_path, capsys):
encoding="utf-8",
)
_capture_cmd(_make_args(config=str(cfg)))
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "Connect disabled" in out
assert "Workbench disabled" in out
assert "Package Manager" not in out
@@ -176,7 +177,7 @@ def test_missing_url_says_no_url(self, tmp_path, capsys):
cfg = tmp_path / "vip.toml"
cfg.write_text("[general]\n", encoding="utf-8")
_capture_cmd(_make_args(config=str(cfg)))
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "Connect no URL given" in out
assert "Workbench no URL given" in out
assert "Package Manager no URL given" in out
@@ -193,15 +194,15 @@ def test_no_notes_when_all_products_configured(self, tmp_path, monkeypatch, caps
encoding="utf-8",
)
_capture_cmd(_make_args(config=str(cfg)))
- out = capsys.readouterr().out
- assert "will not be collected" not in out
+ captured = capsys.readouterr()
+ assert "will not be collected" not in captured.out + captured.err
def test_notes_from_url_args(self, tmp_path, monkeypatch, capsys):
"""URL-argument flow generates a temp config; notes should reflect it."""
monkeypatch.chdir(tmp_path)
monkeypatch.delenv("VIP_CONFIG", raising=False)
_capture_cmd(_make_args(package_manager_url="http://localhost:4242/"))
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "Connect disabled" in out
assert "will not be collected" in out
assert "Workbench disabled" in out
@@ -471,6 +472,25 @@ def test_no_verbose_flag_omits_vip_verbose(self, tmp_path):
assert "--vip-verbose" not in cmd
+class TestVerifyPropagatesVerbosity:
+ """The pytest subprocess inherits the CLI verbosity through VIP_VERBOSITY."""
+
+ @pytest.mark.parametrize(
+ ("level", "expected"),
+ [
+ (Verbosity.QUIET, "quiet"),
+ (Verbosity.NORMAL, "normal"),
+ (Verbosity.VERBOSE, "verbose"),
+ ],
+ )
+ def test_env_carries_level(self, tmp_path, level, expected):
+ cfg = tmp_path / "vip.toml"
+ cfg.write_text("[general]\n", encoding="utf-8")
+ set_verbosity(level)
+ _cmd, kwargs = _capture_call(_make_args(config=str(cfg)))
+ assert kwargs["env"][VERBOSITY_ENV_VAR] == expected
+
+
class TestNormalizeCategories:
"""_normalize_categories should accept hyphenated names and reject invalid ones."""
diff --git a/selftests/test_idp.py b/selftests/test_idp.py
index e22c58f48..ce8ba4645 100644
--- a/selftests/test_idp.py
+++ b/selftests/test_idp.py
@@ -8,6 +8,7 @@
from vip.auth import AuthConfigError
from vip.idp import SUPPORTED_IDPS, _fill_snowflake_login, get_idp_strategy
+from vip.output import Verbosity, set_verbosity
class TestGetIdpStrategy:
@@ -344,9 +345,32 @@ def _wait_for_url(_predicate, timeout):
_fill_entra_login(page, "user", "pass")
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "42" in out
+ @pytest.mark.parametrize(
+ ("level", "shown"),
+ [(Verbosity.NORMAL, False), (Verbosity.VERBOSE, True)],
+ )
+ def test_step_logging_only_when_verbose(self, capsys, level, shown):
+ from vip.idp import _fill_entra_login
+
+ set_verbosity(level)
+ page, _locators = self._make_page(
+ display_sign=self._make_locator(count=1, visible=True, text="42")
+ )
+
+ def _wait_for_url(_predicate, timeout):
+ page.url = self._PRODUCT_URL
+
+ page.wait_for_url.side_effect = _wait_for_url
+
+ _fill_entra_login(page, "user", "pass")
+
+ captured = capsys.readouterr()
+ assert (">>> Entra: waiting for email field" in captured.err) is shown
+ assert ">>> Entra: waiting for email field" not in captured.out
+
def test_proof_up_raises_authconfigerror(self):
from vip.idp import _ENTRA_PROOF_UP_TEXT, _fill_entra_login
@@ -591,7 +615,7 @@ def _wait_for_url(_predicate, timeout):
_fill_entra_login(page, "user", "pass")
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "88" in out
page.wait_for_url.assert_called_once()
locators[_ENTRA_SIGN_IN_ANOTHER_WAY].first.click.assert_not_called()
diff --git a/selftests/test_output.py b/selftests/test_output.py
new file mode 100644
index 000000000..9f9ac4cc3
--- /dev/null
+++ b/selftests/test_output.py
@@ -0,0 +1,168 @@
+"""Tests for vip.output: stream choice, verbosity levels, env parsing, log bridge."""
+
+from __future__ import annotations
+
+import logging
+
+import pytest
+
+from vip import output
+from vip.output import Verbosity
+
+
+def test_out_goes_to_stdout_verbatim(capsys):
+ output.out(">>> result")
+ captured = capsys.readouterr()
+ assert captured.out == ">>> result\n"
+ assert captured.err == ""
+
+
+def test_out_without_message_prints_blank_line(capsys):
+ output.out()
+ assert capsys.readouterr().out == "\n"
+
+
+def test_end_is_honoured(capsys):
+ output.out("a", end="")
+ output.info("b", end="")
+ captured = capsys.readouterr()
+ assert captured.out == "a"
+ assert captured.err == "b"
+
+
+@pytest.mark.parametrize("fn", [output.info, output.warn, output.error, output.debug])
+def test_diagnostic_functions_use_stderr(capsys, fn):
+ output.set_verbosity(Verbosity.VERBOSE)
+ fn("msg")
+ captured = capsys.readouterr()
+ assert captured.err == "msg\n"
+ assert captured.out == ""
+
+
+@pytest.mark.parametrize(
+ ("level", "shown"),
+ [
+ (Verbosity.QUIET, {"out", "warn", "error"}),
+ (Verbosity.NORMAL, {"out", "info", "warn", "error"}),
+ (Verbosity.VERBOSE, {"out", "info", "warn", "error", "debug"}),
+ ],
+)
+def test_levels(capsys, level, shown):
+ output.set_verbosity(level)
+ for name in ("out", "info", "warn", "error", "debug"):
+ getattr(output, name)(name)
+ captured = capsys.readouterr()
+ assert set((captured.out + captured.err).split()) == shown
+
+
+def test_set_verbosity_accepts_names():
+ output.set_verbosity("verbose")
+ assert output.get_verbosity() is Verbosity.VERBOSE
+
+
+@pytest.mark.parametrize(
+ ("value", "expected"),
+ [
+ ("quiet", Verbosity.QUIET),
+ ("QUIET", Verbosity.QUIET),
+ (" verbose ", Verbosity.VERBOSE),
+ ("normal", Verbosity.NORMAL),
+ ("bogus", Verbosity.NORMAL),
+ ("", Verbosity.NORMAL),
+ (None, Verbosity.NORMAL),
+ ],
+)
+def test_parse_verbosity(value, expected):
+ assert output.parse_verbosity(value) is expected
+
+
+def test_streams_resolved_at_call_time(capsys):
+ # capsys swaps sys.stdout after import; a stream bound at import would miss it.
+ output.out("late")
+ assert capsys.readouterr().out == "late\n"
+
+
+def _vip_handlers():
+ return [h for h in logging.getLogger("vip").handlers if isinstance(h, output._StderrHandler)]
+
+
+def test_configure_logging_is_idempotent():
+ output.configure_logging()
+ output.configure_logging()
+ assert len(_vip_handlers()) == 1
+ assert logging.getLogger("vip").propagate is False
+
+
+def test_configure_logging_can_keep_propagation():
+ output.configure_logging(propagate=True)
+ assert len(_vip_handlers()) == 1
+ assert logging.getLogger("vip").propagate is True
+
+
+def test_pytest_subprocess_bridges_logging_at_env_level(pytester, monkeypatch):
+ """The pytest run behind ``vip -v verify`` shows vip.* debug logs on stderr."""
+ monkeypatch.setenv(output.VERBOSITY_ENV_VAR, "verbose")
+ pytester.makepyfile(
+ """
+ import logging
+
+ def test_logger_is_bridged():
+ logger = logging.getLogger("vip")
+ assert logger.level == logging.DEBUG
+ assert logger.propagate is True
+ assert any(type(h).__name__ == "_StderrHandler" for h in logger.handlers)
+ """
+ )
+ result = pytester.runpytest_subprocess("-p", "no:cacheprovider")
+ result.assert_outcomes(passed=1)
+
+
+def test_logging_writes_to_stderr_with_format(capsys):
+ output.configure_logging()
+ logging.getLogger("vip.sub").info("hello")
+ captured = capsys.readouterr()
+ assert captured.err == "INFO: hello\n"
+ assert captured.out == ""
+
+
+@pytest.mark.parametrize(
+ ("level", "expected"),
+ [
+ (Verbosity.QUIET, logging.WARNING),
+ (Verbosity.NORMAL, logging.INFO),
+ (Verbosity.VERBOSE, logging.DEBUG),
+ ],
+)
+def test_logging_level_follows_verbosity(level, expected):
+ output.set_verbosity(level)
+ output.configure_logging()
+ assert logging.getLogger("vip").level == expected
+
+
+def test_set_verbosity_retunes_attached_logger():
+ output.configure_logging()
+ output.set_verbosity(Verbosity.VERBOSE)
+ assert logging.getLogger("vip").level == logging.DEBUG
+
+
+def test_quiet_hides_info_log_but_keeps_warning(capsys):
+ output.set_verbosity(Verbosity.QUIET)
+ output.configure_logging()
+ log = logging.getLogger("vip.sub")
+ log.info("hidden")
+ log.warning("shown")
+ assert capsys.readouterr().err == "WARNING: shown\n"
+
+
+@pytest.mark.parametrize(("level", "expected"), [("quiet", False), ("normal", True)])
+def test_vip_verbose_fixture_yields_to_quiet(pytester, monkeypatch, level, expected):
+ """``vip -q verify --verbose`` keeps --vip-verbose diagnostics (Locust log) off."""
+ monkeypatch.setenv(output.VERBOSITY_ENV_VAR, level)
+ pytester.makepyfile(
+ f"""
+ def test_fixture(vip_verbose):
+ assert vip_verbose is {expected}
+ """
+ )
+ result = pytester.runpytest_subprocess("-p", "no:cacheprovider", "--vip-verbose")
+ result.assert_outcomes(passed=1)
diff --git a/selftests/test_scheme_resolution_proxy.py b/selftests/test_scheme_resolution_proxy.py
index 9b3a71427..8fb9ca0f1 100644
--- a/selftests/test_scheme_resolution_proxy.py
+++ b/selftests/test_scheme_resolution_proxy.py
@@ -96,7 +96,7 @@ def boom(*a, **kw):
pc = _inferred_pc()
resolve_url_scheme(pc, proxy=ProxyConfig(url="http://alice:s3cret@proxy.corp:8080"))
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "s3cret" not in out
assert "alice" not in out
# ...but the sanitized proxy host is still named for debugging.
@@ -114,7 +114,7 @@ def boom(*a, **kw):
pc = _inferred_pc()
resolve_url_scheme(pc, proxy=ProxyConfig(url="http://alice:s3cret@proxy.corp:8080"))
- out = capsys.readouterr().out
+ out = capsys.readouterr().err
assert "s3cret" not in out
assert "proxy.corp:8080" in out
diff --git a/src/vip/auth/apikey.py b/src/vip/auth/apikey.py
index aa0314722..1cb621ae3 100644
--- a/src/vip/auth/apikey.py
+++ b/src/vip/auth/apikey.py
@@ -17,6 +17,7 @@
)
from vip.auth.scheme import _httpx_verify_env_aware
+from vip.output import info, warn
from vip.proxy import (
ProxyConfig,
build_proxy_map,
@@ -62,21 +63,21 @@ def _delete_api_key(
if resp.status_code == 404:
continue
if not resp.is_success:
- print(f">>> Warning: {keys_path} returned HTTP {resp.status_code}")
+ warn(f">>> Warning: {keys_path} returned HTTP {resp.status_code}")
continue
for k in resp.json():
if k.get("name") == key_name:
del_resp = client.delete(f"{keys_path}/{k['id']}")
if del_resp.is_success:
- print(">>> API key deleted.\n")
+ info(">>> API key deleted.\n")
else:
- print(
+ warn(
f">>> Warning: DELETE {keys_path}/{k['id']}"
f" returned {del_resp.status_code}"
)
return
break
- print(">>> Warning: Could not find API key to delete.\n")
+ warn(">>> Warning: Could not find API key to delete.\n")
_XSRF_COOKIE_NAMES = ("RSC-XSRF", "RSC-XSRF-legacy")
@@ -142,27 +143,27 @@ def _log_mint_cookie_diagnostic(page: Page, request_url: str) -> None:
current_url = page.url
except PlaywrightError:
current_url = ""
- print(f">>> Mint diagnostic: browser is on {current_url}")
+ info(f">>> Mint diagnostic: browser is on {current_url}")
try:
jar = page.context.cookies() or []
- print(f">>> Mint diagnostic: full cookie jar ({len(jar)} entries):")
+ info(f">>> Mint diagnostic: full cookie jar ({len(jar)} entries):")
for entry in _summarize_cookies(jar):
- print(f" {entry}")
+ info(f" {entry}")
except PlaywrightError as exc:
- print(f">>> Mint diagnostic: could not read cookie jar: {exc}")
+ info(f">>> Mint diagnostic: could not read cookie jar: {exc}")
try:
scoped = page.context.cookies(request_url) or []
- print(f">>> Mint diagnostic: cookies sent to {request_url} ({len(scoped)} entries):")
+ info(f">>> Mint diagnostic: cookies sent to {request_url} ({len(scoped)} entries):")
for entry in _summarize_cookies(scoped):
- print(f" {entry}")
+ info(f" {entry}")
except PlaywrightError as exc:
- print(f">>> Mint diagnostic: could not read scoped cookies: {exc}")
+ info(f">>> Mint diagnostic: could not read scoped cookies: {exc}")
try:
doc_cookie = page.evaluate("() => document.cookie") or ""
doc_names = [p.strip().partition("=")[0] for p in doc_cookie.split(";") if p.strip()]
- print(f">>> Mint diagnostic: document.cookie names: {doc_names}")
+ info(f">>> Mint diagnostic: document.cookie names: {doc_names}")
except PlaywrightError as exc:
- print(f">>> Mint diagnostic: could not read document.cookie: {exc}")
+ info(f">>> Mint diagnostic: could not read document.cookie: {exc}")
def _response_text(resp) -> str:
@@ -193,7 +194,7 @@ def _delete_stale_vip_keys(client, guid: str) -> None:
try:
list_resp = client.get(f"/v1/users/{guid}/keys")
except (httpx.HTTPError, httpx.InvalidURL) as exc:
- print(f">>> Warning: listing stale keys failed: {exc}")
+ warn(f">>> Warning: listing stale keys failed: {exc}")
return
if not list_resp.is_success:
return
@@ -204,7 +205,7 @@ def _delete_stale_vip_keys(client, guid: str) -> None:
except ValueError:
return
if not isinstance(entries, list):
- print(f">>> Warning: key list response was {type(entries).__name__}, not list.")
+ warn(f">>> Warning: key list response was {type(entries).__name__}, not list.")
return
for k in entries:
@@ -225,7 +226,7 @@ def _delete_stale_vip_keys(client, guid: str) -> None:
try:
client.delete(f"/v1/users/{guid}/keys/{key_id}")
except (httpx.HTTPError, httpx.InvalidURL) as exc:
- print(f">>> Warning: could not delete stale key {key_id}: {exc}")
+ warn(f">>> Warning: could not delete stale key {key_id}: {exc}")
def _content_type(resp) -> str:
@@ -258,16 +259,16 @@ def _probe_server_settings(client, base: str, me_status: int, connect_url: str)
try:
probe = client.get("/server_settings")
except httpx.HTTPError as exc:
- print(f">>> Mint diagnostic: /server_settings probe failed: {exc}")
+ info(f">>> Mint diagnostic: /server_settings probe failed: {exc}")
return
probe_ct = _content_type(probe)
probe_url = f"{base}/server_settings"
- print(
+ info(
f">>> Mint diagnostic: GET {probe_url} returned HTTP "
f"{probe.status_code} (content-type: {probe_ct})"
)
if me_status == 404 and probe.status_code == 404:
- print(
+ info(
f">>> Mint diagnostic: both /__api__ endpoints returned 404 — "
f"the configured connect_url ({connect_url}) likely has the "
f"wrong path prefix. Try removing any sub-path (e.g. '/connect') "
@@ -380,7 +381,7 @@ def _resolve_connect_api_base(
if dashboard_path != sub_path:
return connect_url
- print(
+ info(
f">>> Connect dashboard at {connect_url} but API at {root}/__api__/; "
f"using {root} for API calls."
)
@@ -470,19 +471,19 @@ def _create_api_key_via_session(
me_resp = client.get("/v1/user")
if not me_resp.is_success:
me_ct = _content_type(me_resp)
- print(
+ warn(
f">>> Warning: GET {me_url} returned HTTP "
f"{me_resp.status_code} (content-type: {me_ct}): "
f"{_body_snippet(me_resp)}"
)
xsrf_preview = f"{xsrf[:4]}…(len={len(xsrf)})" if xsrf else ""
- print(f">>> Mint diagnostic: X-Rsc-Xsrf header was {xsrf_preview}")
+ info(f">>> Mint diagnostic: X-Rsc-Xsrf header was {xsrf_preview}")
_log_mint_cookie_diagnostic(page, me_url)
_probe_server_settings(client, base, me_resp.status_code, connect_url)
return None
guid = me_resp.json().get("guid")
if not guid:
- print(">>> Warning: Connect did not return a user guid.")
+ warn(">>> Warning: Connect did not return a user guid.")
return None
_delete_stale_vip_keys(client, guid)
@@ -492,7 +493,7 @@ def _create_api_key_via_session(
json={"name": key_name},
)
if not create_resp.is_success:
- print(
+ warn(
f">>> Warning: POST /v1/users/{guid}/keys returned HTTP "
f"{create_resp.status_code}: {_body_snippet(create_resp)}"
)
@@ -507,7 +508,7 @@ def _create_api_key_via_session(
# comes back instead of the created key. Without this guard
# ``.get("key")`` raises ``AttributeError``, which is not in
# the caught tuple below and so crashes auth outright (#561).
- print(
+ warn(
f">>> Warning: POST /v1/users/{guid}/keys returned a "
f"{type(created).__name__}, not an object. A proxy most "
"likely redirected the request with 301/302, which turns "
@@ -519,10 +520,10 @@ def _create_api_key_via_session(
api_key = created.get("key")
if not api_key:
- print(">>> Warning: Connect response did not include a key string.")
+ warn(">>> Warning: Connect response did not include a key string.")
return None
- print(">>> Connect API key created.\n")
+ info(">>> Connect API key created.\n")
return api_key
except (httpx.HTTPError, ValueError, KeyError) as exc:
# httpx.HTTPError catches both transport-level failures (DNS, TCP,
@@ -531,5 +532,5 @@ def _create_api_key_via_session(
# handling: the function is documented to return None on failure
# rather than raising, so vip verify can emit a warning instead of
# crashing during auth setup.
- print(f">>> Warning: Could not create API key: {exc}")
+ warn(f">>> Warning: Could not create API key: {exc}")
return None
diff --git a/src/vip/auth/browser.py b/src/vip/auth/browser.py
index 4ac5041d9..08645730a 100644
--- a/src/vip/auth/browser.py
+++ b/src/vip/auth/browser.py
@@ -21,6 +21,7 @@
from vip.auth.apikey import _delete_api_key
from vip.errors import AuthConfigError
+from vip.output import warn
from vip.proxy import (
ProxyConfig,
build_proxy_map,
@@ -208,7 +209,7 @@ def cleanup(self) -> None:
proxy=self._proxy,
)
except (httpx.HTTPError, httpx.InvalidURL, ValueError, KeyError, AttributeError) as exc:
- print(f">>> Warning: Could not delete API key: {exc}")
+ warn(f">>> Warning: Could not delete API key: {exc}")
if self._tmpdir and Path(self._tmpdir).is_dir():
shutil.rmtree(self._tmpdir, ignore_errors=True)
diff --git a/src/vip/auth/cache.py b/src/vip/auth/cache.py
index 9319a2b9b..e64c34313 100644
--- a/src/vip/auth/cache.py
+++ b/src/vip/auth/cache.py
@@ -21,6 +21,7 @@
from vip.auth.browser import InteractiveAuthSession
from vip.auth.scheme import _httpx_verify_env_aware
from vip.auth.workbench import _on_login_page
+from vip.output import info
from vip.proxy import (
ProxyConfig,
build_proxy_map,
@@ -117,7 +118,7 @@ def prepare_auth_cache(*, announce_skip: bool = True) -> Path | None:
if path is None:
if not announce_skip:
return None
- print(
+ info(
">>> Skipping auth cache: cannot determine a home directory or the working "
"directory; set XDG_CACHE_HOME to enable it."
)
@@ -411,7 +412,7 @@ def _load_cached_auth(
requested_connect_url,
requested_workbench_url,
):
- print(
+ info(
">>> Ignoring cached auth session: requested URLs differ from cached "
f"(cached connect={cached_request_connect_url or '∅'}, "
f"workbench={cached_request_workbench_url or '∅'}; "
@@ -431,14 +432,14 @@ def _load_cached_auth(
proxy=proxy,
)
if probe.is_live is False:
- print(
+ info(
">>> Ignoring cached auth session: the saved browser session no longer "
f"authenticates Workbench at {requested_workbench_url} "
f"({probe.detail}). Re-authenticating."
)
return None
- print(f">>> Reusing cached auth session from {cache_path}")
+ info(f">>> Reusing cached auth session from {cache_path}")
return InteractiveAuthSession(
storage_state_path=cache_path,
api_key=api_key,
@@ -563,9 +564,7 @@ def _save_auth_cache(session: InteractiveAuthSession, cache_path: Path) -> None:
explains *why* minting failed.
"""
if session._connect_url and not session.api_key:
- print(
- ">>> Skipping auth cache: API key minting failed; next run will retry authentication."
- )
+ info(">>> Skipping auth cache: API key minting failed; next run will retry authentication.")
return
# Write the storage state to the cache location, minus long-lived IdP cookies.
@@ -596,7 +595,7 @@ def _save_auth_cache(session: InteractiveAuthSession, cache_path: Path) -> None:
for leftover in (cache_path, meta_path):
with contextlib.suppress(OSError):
leftover.unlink(missing_ok=True)
- print(
+ info(
f">>> Skipping auth cache: cannot write {cache_path.parent} ({exc}); "
"next run will re-authenticate."
)
diff --git a/src/vip/auth/flows.py b/src/vip/auth/flows.py
index 13f661859..2a9110977 100644
--- a/src/vip/auth/flows.py
+++ b/src/vip/auth/flows.py
@@ -20,7 +20,6 @@
TimeoutError as PlaywrightTimeoutError,
)
-import vip.idp
from vip import totp
from vip.auth.apikey import _KEY_NAME_PREFIX, _create_api_key_via_session, _resolve_connect_api_base
from vip.auth.browser import InteractiveAuthSession, _launch_chromium
@@ -36,7 +35,8 @@
from vip.auth.workbench import _authenticate_workbench, _wait_for_product_redirect
from vip.config import ProductConfig
from vip.errors import AuthConfigError, AuthTimeoutError
-from vip.idp import SUPPORTED_IDPS, _log_verbose, _sanitize_url, get_idp_strategy
+from vip.idp import SUPPORTED_IDPS, _sanitize_url, get_idp_strategy
+from vip.output import Verbosity, debug, get_verbosity, info, set_verbosity, warn
from vip.proxy import (
ProxyConfig,
build_proxy_map,
@@ -302,9 +302,9 @@ def start_interactive_auth(
def login(page: Page, primary_url: str, target: str, has_connect: bool) -> None:
page.goto(target)
- print(f"\n>>> A browser window has opened at {primary_url}")
- print(">>> Please log in through your identity provider.")
- print(">>> The browser will close automatically after login.\n")
+ warn(f"\n>>> A browser window has opened at {primary_url}")
+ warn(">>> Please log in through your identity provider.")
+ warn(">>> The browser will close automatically after login.\n")
# Poll until login completes
base = primary_url.rstrip("/")
@@ -396,7 +396,9 @@ def start_headless_auth(
*connect_url_scheme_inferred* / *workbench_url_scheme_inferred*: see
``start_interactive_auth``.
"""
- vip.idp._verbose = verbose
+ # ``-q`` wins over the legacy ``--vip-verbose`` flag, matching the CLI's precedence.
+ if verbose and get_verbosity() is not Verbosity.QUIET:
+ set_verbosity(Verbosity.VERBOSE)
if not connect_url and not workbench_url:
raise AuthConfigError(
@@ -436,16 +438,16 @@ def start_headless_auth(
fill_login = get_idp_strategy(idp)
def login(page: Page, primary_url: str, target: str, has_connect: bool) -> None:
- print(f"\n>>> Headless auth: authenticating to {primary_url} ...", flush=True)
+ info(f"\n>>> Headless auth: authenticating to {primary_url} ...")
try:
page.goto(target)
page.wait_for_load_state("domcontentloaded")
- _log_verbose(f">>> Page loaded, URL: {_sanitize_url(page.url)}")
+ debug(f">>> Page loaded, URL: {_sanitize_url(page.url)}")
if fill_login:
# OIDC/SAML: navigate to IdP and automate its login form.
_navigate_to_idp(page, primary_url)
- _log_verbose(f">>> At IdP login page: {_sanitize_url(page.url)}")
+ debug(f">>> At IdP login page: {_sanitize_url(page.url)}")
fill_login(page, username, password)
else:
# Password/LDAP: fill the product's native login form directly.
@@ -465,7 +467,7 @@ def login(page: Page, primary_url: str, target: str, has_connect: bool) -> None:
raise AuthConfigError(
f"Headless auth failed during login: {exc}. Rerun with --verbose for details."
) from exc
- print(">>> Authentication complete.")
+ info(">>> Authentication complete.")
return _run_login(
connect_url=connect_url,
diff --git a/src/vip/auth/scheme.py b/src/vip/auth/scheme.py
index a678eb89e..ef58652a5 100644
--- a/src/vip/auth/scheme.py
+++ b/src/vip/auth/scheme.py
@@ -10,6 +10,7 @@
import httpx
+from vip.output import warn
from vip.proxy import (
ProxyConfig,
build_proxy_map,
@@ -213,7 +214,7 @@ def resolve_url_scheme(
# A proxy failure is not evidence about the origin's TLS. Never
# downgrade; the raw-socket tiebreak would bypass the proxy and
# mislead. Keep https:// and point at the proxy as the culprit.
- print(
+ warn(
f">>> Warning: {url} could not be reached through the configured "
f"proxy ({safe_proxy}): {exc}. NOT falling back to plaintext "
f"HTTP -- the proxy, not the server's TLS, is the likely problem. "
@@ -227,7 +228,7 @@ def resolve_url_scheme(
# (e.g. a read timeout mid-tunnel). The raw-socket tiebreak
# bypasses the proxy, so its verdict is about a path we will
# never take -- refuse to downgrade rather than trust it.
- print(
+ warn(
f">>> Warning: {url} did not answer through the configured "
f"proxy ({safe_proxy}): {exc}. NOT falling back to "
f"plaintext HTTP while a proxy is in effect. Verify the proxy "
@@ -235,7 +236,7 @@ def resolve_url_scheme(
f"is genuinely plaintext."
)
elif _tls_listener_present(url, timeout=scaled(5.0)):
- print(
+ warn(
f">>> Warning: {url} answers on the network but its TLS "
f"certificate was not accepted ({exc}). NOT falling back to "
f"plaintext HTTP -- that would send credentials to this server "
@@ -246,7 +247,7 @@ def resolve_url_scheme(
)
else:
resolved = "http://" + url.removeprefix("https://")
- print(
+ warn(
f">>> Warning: {url} did not answer ({exc}); falling back to plaintext "
f"HTTP at {resolved}. Pass an explicit http:// or https:// scheme on the "
f"URL to silence this."
diff --git a/src/vip/auth/sso.py b/src/vip/auth/sso.py
index 109c6d31b..9dff39ca6 100644
--- a/src/vip/auth/sso.py
+++ b/src/vip/auth/sso.py
@@ -11,7 +11,7 @@
Page,
)
-from vip.idp import _log_verbose
+from vip.output import debug
from vip.timeouts import scaled
# Single timeout for an IdP login round-trip (browser leaves the product,
@@ -75,12 +75,12 @@ def _fill_product_login(page: Page, username: str, password: str) -> None:
"button:has-text('Sign in'), button:has-text('Log in')"
)
- _log_verbose(">>> Filling product login form ...")
+ debug(">>> Filling product login form ...")
page.locator(username_selectors).first.wait_for(timeout=int(scaled(15_000)))
page.locator(username_selectors).first.fill(username)
page.locator(password_selectors).first.fill(password)
page.locator(submit_selectors).first.click()
- _log_verbose(">>> Product login form submitted.")
+ debug(">>> Product login form submitted.")
def _strip_url_query(url: str) -> str:
diff --git a/src/vip/auth/workbench.py b/src/vip/auth/workbench.py
index 9ef1e3117..445a8e745 100644
--- a/src/vip/auth/workbench.py
+++ b/src/vip/auth/workbench.py
@@ -19,7 +19,7 @@
_timeout_label,
)
from vip.errors import AuthConfigError, AuthTimeoutError
-from vip.idp import _log_verbose
+from vip.output import debug, info, warn
from vip.timeouts import scaled
# Connect's SPA can take a moment after the OAuth callback before /__api__/me
@@ -133,7 +133,7 @@ def _click_workbench_oidc_confirm(page: Page) -> bool:
btn = page.locator(selector)
if btn.count() == 0 or not btn.first.is_visible():
return False
- _log_verbose(">>> Workbench: clicking 'Sign in with OpenID' to complete OIDC flow ...")
+ debug(">>> Workbench: clicking 'Sign in with OpenID' to complete OIDC flow ...")
btn.first.click()
return True
except PlaywrightError:
@@ -211,14 +211,14 @@ def _authenticate_workbench(page: Page, workbench_url: str, *, provider: str = "
the underlying cause instead of guessing.
"""
wb_base = workbench_url.rstrip("/").lower()
- print(f"\n>>> Authenticating to Workbench at {workbench_url} ...")
+ info(f"\n>>> Authenticating to Workbench at {workbench_url} ...")
try:
page.goto(workbench_url)
page.wait_for_load_state("networkidle")
except PlaywrightError as exc:
reason = f"could not reach Workbench at {workbench_url}: {exc}"
- print(
+ warn(
f">>> Warning: Could not reach Workbench at {workbench_url}: {exc}\n"
">>> Verify the URL is correct and accessible. "
"Workbench tests may be skipped.\n"
@@ -228,7 +228,7 @@ def _authenticate_workbench(page: Page, workbench_url: str, *, provider: str = "
# Quick check — already on the Workbench dashboard?
url = page.url
if url.lower().startswith(wb_base) and not _on_login_page(url):
- print(f">>> Workbench authenticated via SSO. Landed at: {url}\n")
+ info(f">>> Workbench authenticated via SSO. Landed at: {url}\n")
return None
# We're likely on /auth-sign-in. Try clicking a sign-in button to
@@ -247,8 +247,8 @@ def _authenticate_workbench(page: Page, workbench_url: str, *, provider: str = "
continue
# Wait for the OIDC redirect chain to complete.
- print(">>> Waiting for Workbench SSO redirect chain ...")
- print(">>> If prompted, please complete authentication in the browser.\n")
+ warn(">>> Waiting for Workbench SSO redirect chain ...")
+ warn(">>> If prompted, please complete authentication in the browser.\n")
# Share the single round-trip timeout (see _IDP_ROUNDTRIP_TIMEOUT_SECONDS)
# rather than this function's own, shorter one.
@@ -264,7 +264,7 @@ def _authenticate_workbench(page: Page, workbench_url: str, *, provider: str = "
except PlaywrightError:
break
if last_url.lower().startswith(wb_base) and not _on_login_page(last_url):
- print(f">>> Workbench authenticated. Landed at: {last_url}\n")
+ info(f">>> Workbench authenticated. Landed at: {last_url}\n")
return None
try:
page.wait_for_timeout(500)
@@ -278,7 +278,7 @@ def _authenticate_workbench(page: Page, workbench_url: str, *, provider: str = "
last_title = ""
label = _protocol_label(provider)
session_desc = f"{label} session" if label else "The login session"
- print(
+ warn(
f">>> Warning: Workbench authentication did not complete within {timeout_label}.\n"
">>> Workbench browser tests may skip.\n"
)
diff --git a/src/vip/cli/app.py b/src/vip/cli/app.py
index 89dad17c9..b45b46475 100644
--- a/src/vip/cli/app.py
+++ b/src/vip/cli/app.py
@@ -17,6 +17,7 @@
from vip.cli.verify import _IDP_PROVIDERS, DEFAULT_TEST_TIMEOUT_SECONDS, run_verify
from vip.cli.version import run_version
from vip.errors import VipError
+from vip.output import Verbosity, configure_logging, error, set_verbosity
def _reorder_help_args(argv: list[str], commands: set[str]) -> list[str]:
@@ -56,6 +57,27 @@ def main() -> None:
version=f"%(prog)s {__version__}",
help="Print the vip version and exit",
)
+ # Distinct dests: a subparser default with the same dest would overwrite these
+ # (``vip verify --verbose`` has its own ``verbose`` dest).
+ verbosity_group = parser.add_mutually_exclusive_group()
+ verbosity_group.add_argument(
+ "-q",
+ "--quiet",
+ action="store_true",
+ default=False,
+ dest="output_quiet",
+ help="Hide progress messages; show only results, warnings and errors."
+ " Give it before the subcommand (vip -q verify). Wins over --verbose.",
+ )
+ verbosity_group.add_argument(
+ "-v",
+ "--verbose",
+ action="store_true",
+ default=False,
+ dest="output_verbose",
+ help="Also show diagnostic output (auth steps, cache details)."
+ " Give it before the subcommand (vip -v verify).",
+ )
subparsers = parser.add_subparsers(dest="command")
# vip version
@@ -293,7 +315,8 @@ def main() -> None:
"--verbose",
action="store_true",
default=False,
- help="Show full pytest tracebacks instead of concise error messages",
+ help="Show full pytest tracebacks instead of concise error messages and enable"
+ " diagnostic output (same as vip -v verify, plus tracebacks)",
)
verify_parser.add_argument(
"--extensions",
@@ -633,8 +656,13 @@ def main() -> None:
else:
parser.print_help()
sys.exit(1)
+ if args.output_quiet:
+ set_verbosity(Verbosity.QUIET)
+ elif args.output_verbose or getattr(args, "verbose", False):
+ set_verbosity(Verbosity.VERBOSE)
+ configure_logging()
try:
args.func(args)
except VipError as exc:
- print(f"Error: {exc}", file=sys.stderr)
+ error(f"Error: {exc}")
sys.exit(exc.exit_code)
diff --git a/src/vip/cli/auth.py b/src/vip/cli/auth.py
index ca290a3f7..21f77b44d 100644
--- a/src/vip/cli/auth.py
+++ b/src/vip/cli/auth.py
@@ -7,6 +7,7 @@
import sys
from vip.auth import start_interactive_auth
+from vip.output import error, out
def mint_connect_key(args: argparse.Namespace) -> None:
@@ -18,7 +19,7 @@ def mint_connect_key(args: argparse.Namespace) -> None:
# success output is JSON on stdout, so its failure output stays JSON on
# stderr too instead of the central handler's plain-text "Error: ..." --
# a script parsing this command's failures expects {"error": "..."}.
- print(json.dumps({"error": "Failed to mint API key"}), file=sys.stderr)
+ error(json.dumps({"error": "Failed to mint API key"}))
sys.exit(1)
result = {
@@ -26,4 +27,4 @@ def mint_connect_key(args: argparse.Namespace) -> None:
"key_name": session.key_name,
}
- print(json.dumps(result))
+ out(json.dumps(result))
diff --git a/src/vip/cli/bundle.py b/src/vip/cli/bundle.py
index 244d35b4d..3397984cf 100644
--- a/src/vip/cli/bundle.py
+++ b/src/vip/cli/bundle.py
@@ -7,7 +7,6 @@
import json
import os
import re
-import sys
import tomllib
from datetime import UTC, datetime
from pathlib import Path
@@ -39,6 +38,7 @@
from vip.cli.version import _format_version_details
from vip.config import VIPConfig, config_from_raw
from vip.errors import BundleError
+from vip.output import out, warn
_PRODUCTS = ("connect", "workbench", "package_manager")
@@ -444,15 +444,15 @@ def run_bundle(args: argparse.Namespace) -> None:
raise _hit_error(manifest_hits, collected)
for warning in warnings:
- print(f"Warning: {warning}", file=sys.stderr)
+ warn(f"Warning: {warning}")
try:
write_zip(output, members)
except OSError as exc:
raise BundleError(
f"could not write {output}: {exc}. Pass --output PATH to write it somewhere else."
) from exc
- print(f"Bundle written: {output} ({len(members)} files)")
- print(
+ out(f"Bundle written: {output} ({len(members)} files)")
+ out(
f"The secret scan looked for {len(secrets)} known values: "
f"{scan_sources['configuration_and_environment']} from the configuration and the "
f"environment, {scan_sources['results_product_urls']} from the product URLs in "
diff --git a/src/vip/cli/cleanup.py b/src/vip/cli/cleanup.py
index f0415dd2a..c4f6def8f 100644
--- a/src/vip/cli/cleanup.py
+++ b/src/vip/cli/cleanup.py
@@ -3,9 +3,7 @@
from __future__ import annotations
import argparse
-import logging
import os
-import sys
from pathlib import Path
from vip.auth import (
@@ -25,6 +23,7 @@
ConfigError,
ProductUnreachableError,
)
+from vip.output import info, warn
from vip.workbench_ui import quit_vip_sessions_via_ui
@@ -45,14 +44,12 @@ def _cleanup_workbench_sessions_via_token(workbench_url: str, config: VIPConfig)
)
username = config.auth.username
try:
- print(f"Cleaning up orphaned Workbench sessions at {workbench_url} with the API token")
+ info(f"Cleaning up orphaned Workbench sessions at {workbench_url} with the API token")
quit_count = client.quit_vip_sessions_via_api(username)
- print(f"Quit {quit_count} VIP Workbench session(s) via the API token")
+ info(f"Quit {quit_count} VIP Workbench session(s) via the API token")
return not client.vip_sessions_via_api(username)
except ProductUnreachableError as exc:
- print(
- f"The API token could not clean up sessions ({exc}); falling back to browser sign-in."
- )
+ warn(f"The API token could not clean up sessions ({exc}); falling back to browser sign-in.")
return False
finally:
client.close()
@@ -131,7 +128,7 @@ def _cleanup_workbench_sessions(
) from exc
try:
- print(f"Cleaning up orphaned Workbench sessions at {workbench_url}")
+ info(f"Cleaning up orphaned Workbench sessions at {workbench_url}")
cookies = session.load_cookies()
client = WorkbenchClient(
workbench_url, cookies=cookies, insecure=insecure, ca_bundle=ca_bundle, proxy=proxy
@@ -148,7 +145,7 @@ def _cleanup_workbench_sessions(
api_reachable = False
if api_reachable:
quit_count = client.quit_vip_sessions()
- print(f"Quit {quit_count} VIP Workbench session(s) via the API")
+ info(f"Quit {quit_count} VIP Workbench session(s) via the API")
try:
remaining = client.count_vip_sessions()
except ProductUnreachableError:
@@ -161,36 +158,18 @@ def _cleanup_workbench_sessions(
# UI sweep, so an unparseable API response can never silently orphan
# sessions (issue #467).
if not api_reachable or remaining != 0:
- print("Escalating to browser-driven session cleanup ...")
+ info("Escalating to browser-driven session cleanup ...")
with authenticated_page(
session, insecure=insecure, ca_bundle=ca_bundle, proxy=proxy
) as page:
ui_count = quit_vip_sessions_via_ui(page, workbench_url)
- print(f"Quit {ui_count} VIP Workbench session(s) via the UI")
+ info(f"Quit {ui_count} VIP Workbench session(s) via the UI")
finally:
client.close()
finally:
session.cleanup()
-def _ensure_cli_logging() -> None:
- """Route ``vip.*`` INFO/WARNING logs to stderr for the cleanup command.
-
- The session-cleanup path (WorkbenchClient + workbench_ui) emits progress
- and "sessions still present" warnings via ``logging``; without a handler
- those are invisible (or only WARNING via the lastResort handler). Attach a
- single stderr handler to the ``vip`` logger so ``vip cleanup`` surfaces
- what it did. Idempotent: only configures once.
- """
- vip_logger = logging.getLogger("vip")
- if not vip_logger.handlers:
- handler = logging.StreamHandler(sys.stderr)
- handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
- vip_logger.addHandler(handler)
- vip_logger.setLevel(logging.INFO)
- vip_logger.propagate = False
-
-
def _load_cleanup_config(args: argparse.Namespace) -> VIPConfig:
"""Load ``vip.toml`` if present, else a default ``VIPConfig``.
@@ -233,8 +212,6 @@ def run_cleanup(args: argparse.Namespace) -> None:
falls back to ``http://`` if https doesn't answer (see
``vip.config._normalize_url`` / ``vip.auth.resolve_url_scheme``).
"""
- _ensure_cli_logging()
-
connect_arg = getattr(args, "connect_url", None)
api_key = getattr(args, "api_key", None) or os.environ.get("VIP_CONNECT_API_KEY", "")
workbench_arg = getattr(args, "workbench_url", None)
@@ -273,7 +250,7 @@ def run_cleanup(args: argparse.Namespace) -> None:
connect_url = resolve_url_scheme(
connect_pc, insecure=config.insecure, ca_bundle=config.ca_bundle, proxy=config.proxy
)
- print(f"Cleaning up VIP test content on Connect at {connect_url}")
+ info(f"Cleaning up VIP test content on Connect at {connect_url}")
with ConnectClient(
connect_url,
api_key,
@@ -282,7 +259,7 @@ def run_cleanup(args: argparse.Namespace) -> None:
proxy=config.proxy,
) as client:
deleted = client.cleanup_vip_content()
- print(f"Deleted {deleted} VIP test content item(s)")
+ info(f"Deleted {deleted} VIP test content item(s)")
if workbench_pc.url:
workbench_url = resolve_url_scheme(
@@ -290,4 +267,4 @@ def run_cleanup(args: argparse.Namespace) -> None:
)
_cleanup_workbench_sessions(workbench_url, args, config)
- print("Cleanup completed successfully")
+ info("Cleanup completed successfully")
diff --git a/src/vip/cli/install.py b/src/vip/cli/install.py
index 0ac9fb194..7650d83c5 100644
--- a/src/vip/cli/install.py
+++ b/src/vip/cli/install.py
@@ -28,6 +28,7 @@
from vip.install.plan import build_install_plan, build_uninstall_plan
from vip.install.playwright import PlaywrightInstallError, chromium_installed, default_cache_dir
from vip.install.runner import execute_install_plan, execute_uninstall_plan, format_install_plan
+from vip.output import out, warn
def run_install(args: argparse.Namespace) -> None:
@@ -50,7 +51,7 @@ def run_install(args: argparse.Namespace) -> None:
)
if getattr(args, "dry_run", False):
- print(format_install_plan(plan), end="")
+ out(format_install_plan(plan), end="")
return
if manifest is None:
@@ -118,10 +119,9 @@ def run_uninstall(args: argparse.Namespace) -> None:
try:
cfg = load_config()
except (tomllib.TOMLDecodeError, ValueError) as exc:
- print(
+ warn(
f"warning: failed to load vip.toml for chained cleanup: {exc}; "
"continuing without vip.toml-derived settings",
- file=sys.stderr,
)
# A CLI --connect-url wins over vip.toml's [connect] url; wrapping it in
diff --git a/src/vip/cli/report.py b/src/vip/cli/report.py
index 25e6936e1..6d219e2e4 100644
--- a/src/vip/cli/report.py
+++ b/src/vip/cli/report.py
@@ -15,6 +15,7 @@
from vip.bundle.archive import RENDERED_FILES
from vip.bundle.stamp import clear_render_stamp, record_rendered, results_digest
from vip.errors import ReportError
+from vip.output import info, out, warn
# Quarto report template files copied into the working report/ directory.
# Keep in sync with the force-include block in pyproject.toml. The fonts are
@@ -102,9 +103,8 @@ def _ensure_report_templates(report_dir: Path) -> bool:
replaced += _copy_report_templates(repo_report, report_dir)
if replaced:
- print(
+ info(
f"Refreshed report templates in {report_dir}: {', '.join(replaced)}",
- file=sys.stderr,
)
# True only if the working directory now has the complete set (from a
@@ -197,21 +197,20 @@ def run_report(args: argparse.Namespace) -> None:
"(https://quarto.org/docs/get-started/) and re-run."
)
- print(f"Report generated: {output}")
+ out(f"Report generated: {output}")
_stamp(output_dir, digest, before, ("index.html", "details.html"))
# The PDF is the copy customers archive, so a missing one warns loudly —
# but never fails the command, and never blocks the HTML hand-off above.
pdf = report_dir / "_output" / "vip-report.pdf"
if _quarto_render("vip-report.qmd", report_dir, env) == 0 and pdf.exists():
- print(f"PDF generated: {pdf}")
+ out(f"PDF generated: {pdf}")
_stamp(output_dir, digest, before, ("vip-report.pdf",))
else:
- print(
+ warn(
f"Warning: the HTML report rendered but {pdf} did not. "
"Quarto compiles it with Typst, which ships with Quarto 1.4 and "
"later — check `quarto --version` and upgrade if it is older.",
- file=sys.stderr,
)
if args.open:
@@ -239,18 +238,16 @@ def _stamp(
name for name in names if _file_time(output_dir / name) not in (None, before.get(name))
)
for name in sorted(set(names) - set(fresh)):
- print(
+ warn(
f"Warning: this render did not write {output_dir / name}, so "
"'vip bundle' will not include it.",
- file=sys.stderr,
)
try:
record_rendered(output_dir, digest, fresh)
except OSError as exc:
- print(
+ warn(
f"Warning: could not write the render stamp in {output_dir}: {exc}. "
"'vip bundle' will leave out the rendered report.",
- file=sys.stderr,
)
diff --git a/src/vip/cli/scaffold.py b/src/vip/cli/scaffold.py
index 2b531fcec..58ce7351e 100644
--- a/src/vip/cli/scaffold.py
+++ b/src/vip/cli/scaffold.py
@@ -6,13 +6,13 @@
import contextlib
import importlib.resources
import shutil
-import sys
from pathlib import Path
from vip.errors import (
ConfigError,
VipError,
)
+from vip.output import out, warn
# Registry of scaffold templates: name -> (examples/ source directory, one-line
# description). "cross-product" is the default so existing `vip scaffold
@@ -91,9 +91,9 @@ def _scaffold_next_steps(template: str, dest: Path) -> str:
def run_scaffold(args: argparse.Namespace) -> None:
"""Copy a scaffold template to a user-specified directory, or list templates."""
if getattr(args, "list", False):
- print("Available templates:\n")
+ out("Available templates:\n")
for name, (_dirname, description) in _SCAFFOLD_TEMPLATES.items():
- print(f" {name} - {description}")
+ out(f" {name} - {description}")
return
template = getattr(args, "template", None) or _DEFAULT_SCAFFOLD_TEMPLATE
@@ -134,11 +134,10 @@ def run_scaffold(args: argparse.Namespace) -> None:
# Don't fail the scaffold over it -- the tests themselves are still
# usable -- but say so, because a silently missing AGENTS.md means a
# packaging regression that is otherwise invisible to the user.
- print(
+ warn(
"Warning: could not locate examples/_shared/AGENTS.md; "
"the scaffolded directory has no extension-authoring guide.",
- file=sys.stderr,
)
- print(f"Scaffolded extension to: {dest}")
- print(_scaffold_next_steps(template, dest))
+ out(f"Scaffolded extension to: {dest}")
+ out(_scaffold_next_steps(template, dest))
diff --git a/src/vip/cli/status.py b/src/vip/cli/status.py
index bfb7b7ad3..1cdab25ea 100644
--- a/src/vip/cli/status.py
+++ b/src/vip/cli/status.py
@@ -11,6 +11,7 @@
from vip.clients.packagemanager import PackageManagerClient
from vip.clients.workbench import WorkbenchClient
from vip.config import VIPConfig, load_config
+from vip.output import out
def _collect_status(config: VIPConfig) -> dict:
@@ -91,7 +92,7 @@ def run_status(args: argparse.Namespace) -> None:
data = _collect_status(config)
if getattr(args, "json", False):
- print(json.dumps(data))
+ out(json.dumps(data))
else:
for name, product in data["products"].items():
state = product["state"]
@@ -101,6 +102,6 @@ def run_status(args: argparse.Namespace) -> None:
detail = f"HTTP {product['http_status']}"
else:
detail = product.get("detail", "")
- print(f" {state.upper():4s} {name:20s} {detail}")
+ out(f" {state.upper():4s} {name:20s} {detail}")
sys.exit(data["exit_status"])
diff --git a/src/vip/cli/verify.py b/src/vip/cli/verify.py
index 30e656fb0..25f0e7b9f 100644
--- a/src/vip/cli/verify.py
+++ b/src/vip/cli/verify.py
@@ -21,6 +21,7 @@
ConfigError,
VipError,
)
+from vip.output import VERBOSITY_ENV_VAR, get_verbosity, info
from vip.proxy import proxy_env_for_subprocess
from vip.reporting import VALID_FORMATS
from vip.timeouts import scaled
@@ -147,7 +148,7 @@ def _print_skip_notes(cfg: VIPConfig) -> None:
for name, pc in products:
if not pc.is_configured:
reason = "disabled" if not pc.enabled else "no URL given"
- print(f"Note: {name} {reason} — {name} tests will not be collected.", flush=True)
+ info(f"Note: {name} {reason} — {name} tests will not be collected.")
def _check_credentials(
@@ -662,6 +663,8 @@ def _run_pytest(
# Chromium's own detection) takes the same route as the pooled clients that
# read the config directly.
subprocess_env = proxy_env_for_subprocess(cfg.proxy, os.environ)
+ # The pytest plugin's auth code reads the level from the environment.
+ subprocess_env[VERBOSITY_ENV_VAR] = get_verbosity().name.lower()
try:
result = subprocess.run(cmd, timeout=args.test_timeout, env=subprocess_env, check=False)
diff --git a/src/vip/cli/version.py b/src/vip/cli/version.py
index c7300ae1d..715baff29 100644
--- a/src/vip/cli/version.py
+++ b/src/vip/cli/version.py
@@ -5,6 +5,7 @@
import argparse
from vip import __version__
+from vip.output import out
from vip.version import MINIMUM_SUPPORTED_POSIT_TEAM
@@ -23,4 +24,4 @@ def _format_version_details() -> str:
def run_version(_args: argparse.Namespace) -> None:
"""Print the vip version and the minimum supported Posit Team version."""
- print(_format_version_details())
+ out(_format_version_details())
diff --git a/src/vip/fixtures.py b/src/vip/fixtures.py
index d7af496a0..13eaff99a 100644
--- a/src/vip/fixtures.py
+++ b/src/vip/fixtures.py
@@ -77,6 +77,7 @@
from vip.clients.workbench import WorkbenchClient
from vip.config import PerformanceConfig, VIPConfig
from vip.errors import ConfigError
+from vip.output import Verbosity, get_verbosity
from vip.proxy import build_proxy_map, chromium_launch_args, playwright_proxy
from vip.stash import (
_auth_mode_key,
@@ -97,8 +98,12 @@ def vip_config(request: pytest.FixtureRequest) -> VIPConfig:
@pytest.fixture(scope="session")
def vip_verbose(request: pytest.FixtureRequest) -> bool:
- """Whether --vip-verbose was passed on the command line."""
- return request.config.getoption("--vip-verbose", default=False)
+ """Whether --vip-verbose was passed and ``-q`` (``VIP_VERBOSITY=quiet``) was not.
+
+ Gates test-side diagnostics such as the Locust request log, so quiet mode wins.
+ """
+ verbose = bool(request.config.getoption("--vip-verbose", default=False))
+ return verbose and get_verbosity() is not Verbosity.QUIET
# ---------------------------------------------------------------------------
diff --git a/src/vip/idp.py b/src/vip/idp.py
index 0fdc213c3..f3f8f29fa 100644
--- a/src/vip/idp.py
+++ b/src/vip/idp.py
@@ -17,6 +17,7 @@
from vip import totp
from vip.errors import AuthConfigError
+from vip.output import debug, warn
from vip.timeouts import scaled, timeout_scale
# Keycloak selectors — validated by PPM's e2e test suite.
@@ -55,21 +56,6 @@
_MFA_TIMEOUT = 300_000 # 5 minutes
-def _print_flush(msg: str) -> None:
- """Print a message and flush immediately so it appears in subprocess output."""
- print(msg, flush=True)
-
-
-# Module-level verbose flag, set by start_headless_auth before calling strategies.
-_verbose = False
-
-
-def _log_verbose(msg: str) -> None:
- """Print only when verbose mode is active."""
- if _verbose:
- _print_flush(msg)
-
-
def _sanitize_url(url: str) -> str:
"""Return origin + path, stripping query params that may contain secrets."""
parsed = urlparse(url)
@@ -78,27 +64,27 @@ def _sanitize_url(url: str) -> str:
def _fill_keycloak_login(page: Page, username: str, password: str) -> None:
"""Fill Keycloak's single-page login form and handle optional TOTP."""
- _log_verbose(">>> Keycloak: waiting for login form ...")
+ debug(">>> Keycloak: waiting for login form ...")
page.locator(_KC_SUBMIT).wait_for(timeout=_FORM_TIMEOUT)
page.locator(_KC_USERNAME).fill(username)
page.locator(_KC_PASSWORD).fill(password)
page.locator(_KC_SUBMIT).click()
- _log_verbose(">>> Keycloak: credentials submitted.")
+ debug(">>> Keycloak: credentials submitted.")
- _log_verbose(">>> Keycloak: checking for MFA challenge ...")
+ debug(">>> Keycloak: checking for MFA challenge ...")
otp_field = page.locator(_KC_OTP)
try:
otp_field.wait_for(state="visible", timeout=_MFA_DETECT_TIMEOUT)
except PlaywrightTimeout:
- _log_verbose(">>> Keycloak: no MFA challenge detected, proceeding.")
+ debug(">>> Keycloak: no MFA challenge detected, proceeding.")
return
- _log_verbose(">>> Keycloak: obtaining TOTP code ...")
+ debug(">>> Keycloak: obtaining TOTP code ...")
code = totp.get_code(">>> Enter your verification code: ")
otp_field.fill(code)
page.locator(_KC_SUBMIT).click()
- _log_verbose(">>> Keycloak: TOTP code submitted.")
+ debug(">>> Keycloak: TOTP code submitted.")
def _select_totp_authenticator(page: Page) -> None:
@@ -130,7 +116,7 @@ def _select_totp_authenticator(page: Page) -> None:
if select_btn.count() == 0:
select_btn = code_option.get_by_role("button", name="Select")
if select_btn.count() > 0 and select_btn.first.is_visible():
- _log_verbose(">>> Okta: selecting 'Enter a code' authenticator (data-se) ...")
+ debug(">>> Okta: selecting 'Enter a code' authenticator (data-se) ...")
select_btn.first.click()
page.wait_for_load_state("domcontentloaded")
return
@@ -158,25 +144,25 @@ def _select_totp_authenticator(page: Page) -> None:
if select_link.count() == 0:
select_link = container.get_by_role("button", name="Select")
if select_link.count() > 0 and select_link.first.is_visible():
- _log_verbose(">>> Okta: selecting 'Enter a code' authenticator (text) ...")
+ debug(">>> Okta: selecting 'Enter a code' authenticator (text) ...")
select_link.first.click()
page.wait_for_load_state("domcontentloaded")
return
- _log_verbose(">>> Okta: no authenticator selection page detected.")
+ debug(">>> Okta: no authenticator selection page detected.")
def _fill_okta_login(page: Page, username: str, password: str) -> None:
"""Fill Okta's multi-step login form and handle optional MFA."""
# Step 1: identifier page.
- _log_verbose(">>> Okta: waiting for identifier field ...")
+ debug(">>> Okta: waiting for identifier field ...")
page.locator(_OKTA_IDENTIFIER).wait_for(timeout=_FORM_TIMEOUT)
page.locator(_OKTA_IDENTIFIER).fill(username)
page.locator(_OKTA_SUBMIT).first.click()
- _log_verbose(">>> Okta: identifier submitted.")
+ debug(">>> Okta: identifier submitted.")
# Step 2: password page.
- _log_verbose(">>> Okta: waiting for password field ...")
+ debug(">>> Okta: waiting for password field ...")
page.locator(_OKTA_PASSCODE).wait_for(timeout=_FORM_TIMEOUT)
page.locator(_OKTA_PASSCODE).fill(password)
@@ -190,7 +176,7 @@ def _fill_okta_login(page: Page, username: str, password: str) -> None:
heading_before = (heading_el.text_content() or "").lower().strip()
page.locator(_OKTA_SUBMIT).first.click()
- _log_verbose(">>> Okta: password submitted, waiting for response ...")
+ debug(">>> Okta: password submitted, waiting for response ...")
# Step 3: detect what happened after password submission.
#
@@ -216,7 +202,7 @@ def _fill_okta_login(page: Page, username: str, password: str) -> None:
try:
# Check: URL changed (redirect to product).
if page.url != pre_submit_url:
- _log_verbose(f">>> Okta: URL changed to: {_sanitize_url(page.url)}")
+ debug(f">>> Okta: URL changed to: {_sanitize_url(page.url)}")
break
# Check: error banner visible.
@@ -224,14 +210,14 @@ def _fill_okta_login(page: Page, username: str, password: str) -> None:
loc = page.locator(sel.strip())
if loc.count() > 0 and loc.first.is_visible():
error_msg = (loc.first.text_content() or "").strip()
- _log_verbose(f">>> Okta: login error: {error_msg}")
+ debug(f">>> Okta: login error: {error_msg}")
raise AuthConfigError(f"Okta login failed: {error_msg}")
# Check: MFA-specific elements appeared.
for sel in mfa_selectors.split(","):
loc = page.locator(sel.strip())
if loc.count() > 0 and loc.first.is_visible():
- _log_verbose(">>> Okta: MFA authenticator elements detected.")
+ debug(">>> Okta: MFA authenticator elements detected.")
break
else:
# Check: submit button text changed (form transitioned).
@@ -240,7 +226,7 @@ def _fill_okta_login(page: Page, username: str, password: str) -> None:
if submit_loc.count() > 0:
submit_text_now = submit_loc.text_content() or ""
if submit_text_now and submit_text_now != submit_text_before:
- _log_verbose(f">>> Okta: form transitioned (button: {submit_text_now!r})")
+ debug(f">>> Okta: form transitioned (button: {submit_text_now!r})")
break
# Check: heading changed (form transitioned to a new step).
@@ -248,7 +234,7 @@ def _fill_okta_login(page: Page, username: str, password: str) -> None:
if heading_el.count() > 0 and heading_el.is_visible():
heading_now = (heading_el.text_content() or "").lower().strip()
if heading_now and heading_now != heading_before:
- _log_verbose(f">>> Okta: heading changed to: {heading_now!r}")
+ debug(f">>> Okta: heading changed to: {heading_now!r}")
break
page.wait_for_timeout(500)
@@ -260,13 +246,13 @@ def _fill_okta_login(page: Page, username: str, password: str) -> None:
# Transient Playwright error during widget transition — retry.
page.wait_for_timeout(500)
else:
- _log_verbose(f">>> Okta: no state change after 30s: {_sanitize_url(page.url)}")
+ debug(f">>> Okta: no state change after 30s: {_sanitize_url(page.url)}")
raise AuthConfigError(
"Okta login did not respond after password submission. "
"Check credentials and IdP configuration."
)
- _log_verbose(f">>> Okta: password accepted. URL: {_sanitize_url(page.url)}")
+ debug(f">>> Okta: password accepted. URL: {_sanitize_url(page.url)}")
# Determine whether we're in an MFA flow or already redirecting.
current_url = page.url.lower()
@@ -277,10 +263,10 @@ def _fill_okta_login(page: Page, username: str, password: str) -> None:
has_mfa_content = mfa_content.first.is_visible()
if not url_has_mfa and not has_mfa_content:
- _log_verbose(">>> Okta: no MFA challenge detected, proceeding.")
+ debug(">>> Okta: no MFA challenge detected, proceeding.")
return
- _log_verbose(f">>> Okta: MFA challenge detected at {_sanitize_url(page.url)}")
+ debug(f">>> Okta: MFA challenge detected at {_sanitize_url(page.url)}")
# Handle authenticator selection page — Okta may present a list of
# MFA options (TOTP, push, security key). Click "Select" next to
@@ -314,20 +300,20 @@ def _fill_okta_login(page: Page, username: str, password: str) -> None:
page.wait_for_timeout(500)
if totp_field:
- _log_verbose(">>> Okta: TOTP input detected.")
+ debug(">>> Okta: TOTP input detected.")
totp_field.clear()
code = totp.get_code(">>> Enter your verification code: ")
- _log_verbose(">>> Okta: filling TOTP code ...")
+ debug(">>> Okta: filling TOTP code ...")
totp_field.fill(code)
- _log_verbose(">>> Okta: clicking verify ...")
+ debug(">>> Okta: clicking verify ...")
page.locator(_OKTA_SUBMIT).first.click()
- _log_verbose(">>> Okta: TOTP code submitted.")
+ debug(">>> Okta: TOTP code submitted.")
else:
# No TOTP input after selection — fall back to push/wait.
- _log_verbose(">>> Okta: no TOTP input found — assuming push/other MFA factor.")
- print(">>> Approve the notification on your device, then press Enter.", flush=True)
+ debug(">>> Okta: no TOTP input found — assuming push/other MFA factor.")
+ warn(">>> Approve the notification on your device, then press Enter.")
input()
- _log_verbose(">>> Okta: waiting for MFA approval redirect ...")
+ debug(">>> Okta: waiting for MFA approval redirect ...")
page.wait_for_url(
lambda url: "/challenge" not in url.lower(),
timeout=_MFA_TIMEOUT,
@@ -359,7 +345,7 @@ def _fill_snowflake_login(page: Page, username: str, password: str) -> None:
page.locator(_SF_USERNAME).wait_for(state="visible", timeout=timeout)
except PlaywrightTimeout:
# No (further) sign-in form — the chain has moved past Snowflake login.
- _log_verbose(f">>> Snowflake: no sign-in form after {attempt} fill(s); done.")
+ debug(f">>> Snowflake: no sign-in form after {attempt} fill(s); done.")
break
before = page.url
@@ -367,14 +353,14 @@ def _fill_snowflake_login(page: Page, username: str, password: str) -> None:
page.locator(_SF_PASSWORD).fill(password)
# The username/password "Sign in" button is the second one on the page.
page.locator(_SF_SUBMIT).nth(1).click()
- _log_verbose(f">>> Snowflake: submitted sign-in form #{attempt + 1}.")
+ debug(f">>> Snowflake: submitted sign-in form #{attempt + 1}.")
# The first authorization of an OAuth client shows an "Allow" consent.
try:
allow_button = page.get_by_role("button", name=_SF_ALLOW)
allow_button.wait_for(state="visible", timeout=_SF_CONSENT_TIMEOUT)
allow_button.click()
- _log_verbose(">>> Snowflake: clicked 'Allow' consent.")
+ debug(">>> Snowflake: clicked 'Allow' consent.")
except (PlaywrightTimeout, Error):
pass
@@ -516,7 +502,7 @@ def _select_entra_totp_method(page: Page) -> bool:
"""
option = page.locator(_ENTRA_VERIFY_CODE_OPTION)
if option.count() > 0 and option.first.is_visible():
- _log_verbose(">>> Entra: selecting 'Use a verification code' option ...")
+ debug(">>> Entra: selecting 'Use a verification code' option ...")
option.first.click()
return True
@@ -524,7 +510,7 @@ def _select_entra_totp_method(page: Page) -> bool:
for i in range(text_option.count()):
candidate = text_option.nth(i)
if candidate.is_visible():
- _log_verbose(">>> Entra: selecting 'Use a verification code' option (text) ...")
+ debug(">>> Entra: selecting 'Use a verification code' option (text) ...")
candidate.click()
return True
return False
@@ -532,7 +518,7 @@ def _select_entra_totp_method(page: Page) -> bool:
def _entra_handle_otc(page: Page) -> None:
"""Fill and submit a verification-code (TOTP) prompt."""
- _log_verbose(">>> Entra: verification-code prompt detected.")
+ debug(">>> Entra: verification-code prompt detected.")
code = totp.get_code(">>> Enter your verification code: ")
page.locator(_ENTRA_OTC_INPUT).first.fill(code)
submit = page.locator(_ENTRA_OTC_SUBMIT)
@@ -540,7 +526,7 @@ def _entra_handle_otc(page: Page) -> None:
submit.first.click()
else:
page.locator(_ENTRA_SUBMIT).click()
- _log_verbose(">>> Entra: verification code submitted.")
+ debug(">>> Entra: verification code submitted.")
def _entra_is_push(page: Page) -> bool:
@@ -570,7 +556,7 @@ def _entra_try_switch_from_push(page: Page) -> bool:
link = page.locator(_ENTRA_SIGN_IN_ANOTHER_WAY)
if link.count() > 0 and link.first.is_visible():
- _log_verbose(">>> Entra: switching away from auto-sent push to pick a code ...")
+ debug(">>> Entra: switching away from auto-sent push to pick a code ...")
link.first.click()
return True
@@ -578,7 +564,7 @@ def _entra_try_switch_from_push(page: Page) -> bool:
for i in range(text_link.count()):
candidate = text_link.nth(i)
if candidate.is_visible():
- _log_verbose(">>> Entra: switching away from auto-sent push (text) ...")
+ debug(">>> Entra: switching away from auto-sent push (text) ...")
candidate.click()
return True
return False
@@ -591,16 +577,14 @@ def _entra_handle_push(page: Page) -> None:
display = page.locator(_ENTRA_DISPLAY_SIGN)
if display.count() > 0 and display.first.is_visible():
number = (display.first.text_content() or "").strip()
- print(
+ warn(
f">>> Enter {number} in Microsoft Authenticator to approve sign-in.",
- flush=True,
)
else:
- print(
+ warn(
">>> Approve the sign-in request in Microsoft Authenticator, then wait.",
- flush=True,
)
- _log_verbose(">>> Entra: waiting for push approval ...")
+ debug(">>> Entra: waiting for push approval ...")
before = page.url
def _advanced(url: str, _before: str = before) -> bool:
@@ -627,7 +611,7 @@ def _entra_dismiss_kmsi(page: Page) -> None:
"""
no_button = page.locator(_ENTRA_KMSI_NO)
if no_button.count() > 0 and no_button.first.is_visible():
- _log_verbose(">>> Entra: dismissing 'Stay signed in?' with No ...")
+ debug(">>> Entra: dismissing 'Stay signed in?' with No ...")
no_button.first.click()
@@ -643,7 +627,7 @@ def _entra_resolve_post_password(page: Page) -> None:
mfa_handled = False
while time.monotonic() < deadline:
if _entra_left_login_host(page):
- _log_verbose(f">>> Entra: left login host: {_sanitize_url(page.url)}")
+ debug(f">>> Entra: left login host: {_sanitize_url(page.url)}")
return
_raise_if_entra_error(page)
@@ -693,7 +677,7 @@ def _entra_resolve_post_password(page: Page) -> None:
# Re-check once so a redirect that landed just as the deadline passed isn't
# mistaken for a stuck screen.
if _entra_left_login_host(page):
- _log_verbose(">>> Entra: no further challenge detected within timeout; proceeding.")
+ debug(">>> Entra: no further challenge detected within timeout; proceeding.")
return
raise AuthConfigError(
@@ -730,13 +714,13 @@ def _fill_entra_login(page: Page, username: str, password: str) -> None:
raises ``AuthConfigError`` pointing at configuring the federated IdP
directly, rather than hanging until timeout.
"""
- _log_verbose(">>> Entra: waiting for email field ...")
+ debug(">>> Entra: waiting for email field ...")
page.locator(_ENTRA_USERNAME).wait_for(timeout=_FORM_TIMEOUT)
page.locator(_ENTRA_USERNAME).fill(username)
page.locator(_ENTRA_SUBMIT).click()
- _log_verbose(">>> Entra: email submitted.")
+ debug(">>> Entra: email submitted.")
- _log_verbose(">>> Entra: waiting for password field ...")
+ debug(">>> Entra: waiting for password field ...")
password_field = page.locator(_ENTRA_PASSWORD)
deadline = time.monotonic() + _FORM_TIMEOUT / 1000
while time.monotonic() < deadline:
@@ -760,7 +744,7 @@ def _fill_entra_login(page: Page, username: str, password: str) -> None:
password_field.first.fill(password)
page.locator(_ENTRA_SUBMIT).click()
- _log_verbose(">>> Entra: password submitted.")
+ debug(">>> Entra: password submitted.")
_entra_resolve_post_password(page)
diff --git a/src/vip/install/playwright.py b/src/vip/install/playwright.py
index 989748e9f..adabe9a78 100644
--- a/src/vip/install/playwright.py
+++ b/src/vip/install/playwright.py
@@ -13,6 +13,8 @@
import playwright
+from vip.output import info
+
class PlaywrightInstallError(Exception):
"""Raised when `playwright install chromium` exits nonzero."""
@@ -148,4 +150,4 @@ def install_chromium() -> None:
raise PlaywrightInstallError(f"playwright install chromium exited with exit {rc}")
if filtered:
- print("Installed Playwright Chromium (Playwright fallback build for unsupported-OS hosts).")
+ info("Installed Playwright Chromium (Playwright fallback build for unsupported-OS hosts).")
diff --git a/src/vip/install/runner.py b/src/vip/install/runner.py
index bd0a48eb6..0d17145a1 100644
--- a/src/vip/install/runner.py
+++ b/src/vip/install/runner.py
@@ -20,6 +20,7 @@
UninstallPlan,
)
from vip.install.playwright import install_chromium
+from vip.output import error, out, warn
def is_root() -> bool:
@@ -85,7 +86,7 @@ def execute_install_plan(
I/O, matching ``build_install_plan``. When omitted, requested names are
recorded unchanged.
"""
- print(format_install_plan(plan), end="")
+ out(format_install_plan(plan), end="")
system_step = plan.system_step
needs_root = bool(system_step and system_step.packages)
@@ -107,8 +108,8 @@ def execute_install_plan(
cmd = "sudo zypper -n install"
else:
cmd = "sudo apt install -y"
- print(f"\nNot running as root. Please run:\n {cmd} {' '.join(system_step.packages)}")
- print("Then re-run `vip install`, or pass `--skip-system` to skip this check.")
+ error(f"\nNot running as root. Please run:\n {cmd} {' '.join(system_step.packages)}")
+ error("Then re-run `vip install`, or pass `--skip-system` to skip this check.")
return 2
# Run system step ourselves if root.
@@ -206,9 +207,9 @@ def execute_uninstall_plan(
printed "(content cleanup: failed)" summary line, not the return code, to
detect that case.
"""
- print(format_uninstall_plan(plan), end="")
+ out(format_uninstall_plan(plan), end="")
if not yes:
- print("\nDry run only. Pass --yes to execute.")
+ out("\nDry run only. Pass --yes to execute.")
return 0
cleanup_status = "skipped"
@@ -217,7 +218,7 @@ def execute_uninstall_plan(
cleanup_callable(plan.chained_cleanup)
cleanup_status = "ok"
except Exception as exc: # noqa: BLE001
- print(f"warning: chained vip cleanup failed: {exc}")
+ warn(f"warning: chained vip cleanup failed: {exc}")
cleanup_status = "failed"
for cache_dir in plan.playwright_cache_dirs:
@@ -229,16 +230,16 @@ def execute_uninstall_plan(
manifest_path.unlink()
if plan.system_remove_commands:
- print("\nRun the following yourself to remove system packages:")
+ out("\nRun the following yourself to remove system packages:")
for cmd in plan.system_remove_commands:
- print(f" {cmd}")
+ out(f" {cmd}")
if cleanup_status == "skipped":
- print("\nvip uninstall: complete")
+ out("\nvip uninstall: complete")
else:
- print(f"\nvip uninstall: complete (content cleanup: {cleanup_status})")
+ out(f"\nvip uninstall: complete (content cleanup: {cleanup_status})")
- print(
+ out(
"\nTo also remove vip itself, run one of:\n"
" uv tool uninstall posit-vip # if installed via `uv tool install`\n"
" uv pip uninstall posit-vip # if installed via `uv pip install`"
diff --git a/src/vip/output.py b/src/vip/output.py
new file mode 100644
index 000000000..2caffd9b5
--- /dev/null
+++ b/src/vip/output.py
@@ -0,0 +1,136 @@
+"""Terminal output for the VIP CLI and the code it drives.
+
+Every print goes through here, except the verbatim relay of a child process's
+streams (``install/playwright.py``) and the fd-level Locust writer
+(``load_engine.py``). Command results (data a caller might pipe) go through
+:func:`out`; progress, warnings, errors and diagnostics go to stderr through
+:func:`info`, :func:`warn`, :func:`error` and :func:`debug`. Messages are
+written exactly as given, with no added prefix.
+"""
+
+from __future__ import annotations
+
+import enum
+import logging
+import os
+import sys
+from typing import TextIO
+
+VERBOSITY_ENV_VAR = "VIP_VERBOSITY"
+
+_LOGGER_NAME = "vip"
+_LOG_FORMAT = "%(levelname)s: %(message)s"
+
+
+class Verbosity(enum.IntEnum):
+ """How much :mod:`vip.output` prints; higher shows more."""
+
+ QUIET = 0
+ NORMAL = 1
+ VERBOSE = 2
+
+
+def parse_verbosity(value: str | None) -> Verbosity:
+ """Map a ``quiet``/``normal``/``verbose`` string to a level; anything else is normal."""
+ try:
+ return Verbosity[(value or "").strip().upper()]
+ except KeyError:
+ return Verbosity.NORMAL
+
+
+# Read at import so a subprocess (the pytest run behind ``vip verify``) inherits
+# the parent's level through the environment.
+_verbosity = parse_verbosity(os.environ.get(VERBOSITY_ENV_VAR))
+
+
+class _StderrHandler(logging.StreamHandler):
+ """Stream handler that resolves ``sys.stderr`` per record, not at creation."""
+
+ def __init__(self) -> None:
+ """Create the handler without binding a stream."""
+ logging.Handler.__init__(self)
+ self.setFormatter(logging.Formatter(_LOG_FORMAT))
+
+ @property
+ def stream(self) -> TextIO:
+ """Return the current ``sys.stderr``."""
+ return sys.stderr
+
+ @stream.setter
+ def stream(self, _value: object) -> None:
+ """Ignore assignment; the stream is always ``sys.stderr``."""
+
+
+def get_verbosity() -> Verbosity:
+ """Return the current verbosity level."""
+ return _verbosity
+
+
+def set_verbosity(level: Verbosity | str) -> None:
+ """Set the verbosity level (a :class:`Verbosity` or its name) and retune logging."""
+ global _verbosity
+ _verbosity = parse_verbosity(level) if isinstance(level, str) else Verbosity(level)
+ _sync_logger_level()
+
+
+def _sync_logger_level() -> None:
+ """Point an attached ``vip`` log handler's threshold at the current verbosity."""
+ logger = logging.getLogger(_LOGGER_NAME)
+ if any(isinstance(h, _StderrHandler) for h in logger.handlers):
+ logger.setLevel(_log_level())
+
+
+def _log_level() -> int:
+ """Return the ``logging`` level that matches the current verbosity."""
+ if _verbosity is Verbosity.VERBOSE:
+ return logging.DEBUG
+ if _verbosity is Verbosity.QUIET:
+ return logging.WARNING
+ return logging.INFO
+
+
+def configure_logging(*, propagate: bool = False) -> None:
+ """Send ``vip.*`` log records to stderr at a level that follows the verbosity.
+
+ Idempotent: attaches one handler to the ``vip`` logger however often it is called.
+ Pass ``propagate=True`` inside pytest so its log capture still records ``vip.*``.
+ """
+ logger = logging.getLogger(_LOGGER_NAME)
+ if not any(isinstance(h, _StderrHandler) for h in logger.handlers):
+ logger.addHandler(_StderrHandler())
+ logger.propagate = propagate
+ logger.setLevel(_log_level())
+
+
+def _write(stream_name: str, msg: str, end: str) -> None:
+ """Write *msg* to ``sys.`` (looked up now) and flush it."""
+ stream = getattr(sys, stream_name)
+ stream.write(f"{msg}{end}")
+ stream.flush()
+
+
+def out(msg: str = "", *, end: str = "\n") -> None:
+ """Write a command result (data a caller may pipe) to stdout; always shown."""
+ _write("stdout", msg, end)
+
+
+def info(msg: str = "", *, end: str = "\n") -> None:
+ """Write progress or status to stderr; hidden when quiet."""
+ if _verbosity >= Verbosity.NORMAL:
+ _write("stderr", msg, end)
+
+
+def warn(msg: str = "", *, end: str = "\n") -> None:
+ """Write a warning to stderr; shown at every level."""
+ _write("stderr", msg, end)
+
+
+def error(msg: str = "", *, end: str = "\n") -> None:
+ """Write a failure to stderr; shown at every level."""
+ _write("stderr", msg, end)
+
+
+def debug(msg: str = "", *, end: str = "\n") -> None:
+ """Write a diagnostic to stderr; shown only when verbose."""
+ if _verbosity >= Verbosity.VERBOSE:
+ _write("stderr", msg, end)
diff --git a/src/vip/plugin/configure.py b/src/vip/plugin/configure.py
index eb4cd98ae..e39c0331e 100644
--- a/src/vip/plugin/configure.py
+++ b/src/vip/plugin/configure.py
@@ -12,6 +12,7 @@
from vip.config import load_config
from vip.fixtures import register as _register_fixtures
+from vip.output import configure_logging
from vip.plugin import state
from vip.plugin.auth import _configure_auth
from vip.plugin.terminal import _install_location_shortener, _install_progress_recolor
@@ -36,6 +37,10 @@ def pytest_configure(config: pytest.Config) -> None:
"""
state._active_config = config
+ # Route vip.* logs to stderr at the VIP_VERBOSITY level in this process and every
+ # xdist worker, before auth runs; propagation keeps pytest's log capture working.
+ configure_logging(propagate=True)
+
# Register VIP's core fixtures and shared BDD steps as their own pytest
# plugin (see vip.fixtures' module docstring for why: directory-scoped
# conftest.py fixtures are invisible to extension directories loaded via
diff --git a/src/vip/plugin/results.py b/src/vip/plugin/results.py
index 7eb39a04c..2e5840f4e 100644
--- a/src/vip/plugin/results.py
+++ b/src/vip/plugin/results.py
@@ -7,7 +7,6 @@
import json
import platform
import re
-import sys
import time
import warnings
from datetime import UTC, datetime
@@ -16,6 +15,8 @@
import pytest
+from vip.output import warn
+
try:
from pytest_bdd.scenario import scenario_wrapper_template_registry
except ImportError: # private API; see _scenario_for
@@ -493,12 +494,11 @@ def _apply_unproven_exit_status(session: pytest.Session, exitstatus: int) -> int
reasons = "\n".join(
f" - {r['nodeid']}: {r.get('skip_reason') or 'no reason recorded'}" for r in unproven
)
- print(
+ warn(
f"\nVIP: {len(unproven)} check(s) could not be verified. Nothing failed, "
f"but nothing was proven either:\n{reasons}\n"
"Pass --vip-allow-unproven (or --allow-unproven via `vip verify`) "
"to treat these as an ordinary skip.",
- file=sys.stderr,
)
return EXIT_UNPROVEN
diff --git a/src/vip/proxy.py b/src/vip/proxy.py
index f0bab47ba..fe1408326 100644
--- a/src/vip/proxy.py
+++ b/src/vip/proxy.py
@@ -39,13 +39,13 @@
import re
import ssl
-import sys
from collections.abc import Mapping
from dataclasses import dataclass, field
import httpx
from vip.errors import ConfigError
+from vip.output import info
try:
from httpx._utils import (
@@ -314,13 +314,12 @@ def _promote_http_proxy_to_https(proxy_map: ProxyMap) -> None:
proxy_map["https://"] = http_proxy
if not _promotion_notice_emitted:
_promotion_notice_emitted = True
- print(
+ info(
f">>> Notice: HTTP_PROXY is set ({redact_proxy_url(http_proxy)}) with no "
f"HTTPS_PROXY/ALL_PROXY, so VIP is routing https through it via CONNECT "
f"(curl and httpx would send https direct). Set HTTPS_PROXY/ALL_PROXY to "
f"choose a different gateway, or NO_PROXY for hosts that should be "
f"reached directly.",
- file=sys.stderr,
)
diff --git a/src/vip_tests/connect/test_content_deploy.py b/src/vip_tests/connect/test_content_deploy.py
index 712ad5b92..59217815c 100644
--- a/src/vip_tests/connect/test_content_deploy.py
+++ b/src/vip_tests/connect/test_content_deploy.py
@@ -16,6 +16,7 @@
from pytest_bdd import scenario, then, when
from vip import attest
+from vip.output import info
from vip_tests.connect.bundles import _latest_version, build_shiny_bundle_files
from vip_tests.connect.conftest import _make_tar_gz
@@ -537,7 +538,7 @@ def wait_for_deploy(connect_client, deploy_state, vip_config, record_property):
f"content={deploy_state.get('name', 'unknown')} "
f"code={matched_code} host={matched_host}",
)
- print(
+ info(
f">>> {deploy_state.get('name', 'deploy')}: packrat restore hit a transient "
f"connection failure ({matched_code} against {matched_host}); retrying the "
"deploy once before failing the suite (vip#553)."
diff --git a/src/vip_tests/performance/test_resource_usage.py b/src/vip_tests/performance/test_resource_usage.py
index 08af70f46..19dc2deaf 100644
--- a/src/vip_tests/performance/test_resource_usage.py
+++ b/src/vip_tests/performance/test_resource_usage.py
@@ -3,7 +3,6 @@
from __future__ import annotations
import statistics
-import sys
import time
from concurrent.futures import ThreadPoolExecutor
@@ -12,6 +11,7 @@
from pytest_bdd import given, scenario, then, when
from vip.client_auth import build_client_auth
+from vip.output import info
@scenario(
@@ -71,19 +71,15 @@ def _fetch_loop(url: str, auth: httpx.Auth | None):
elapsed = time.monotonic() - start
results.append({"elapsed": elapsed, "status": resp.status_code, "error": None})
if verbose:
- print(
+ info(
f"[load] GET {url} {resp.status_code} {elapsed:.2f}s",
- file=sys.stderr,
- flush=True,
)
except (httpx.HTTPError, httpx.InvalidURL) as exc:
elapsed = time.monotonic() - start
results.append({"elapsed": elapsed, "status": None, "error": str(exc)})
if verbose:
- print(
+ info(
f"[load] GET {url} FAIL {elapsed:.2f}s {exc}",
- file=sys.stderr,
- flush=True,
)
time.sleep(0.1)
diff --git a/src/vip_tests/workbench/test_publish_to_connect.py b/src/vip_tests/workbench/test_publish_to_connect.py
index 07a96e2b3..275bad3ca 100644
--- a/src/vip_tests/workbench/test_publish_to_connect.py
+++ b/src/vip_tests/workbench/test_publish_to_connect.py
@@ -26,6 +26,7 @@
from vip import attest
from vip.clients.connect import _VIP_CONTENT_TAG
+from vip.output import info
from vip_tests.workbench.conftest import (
TIMEOUT_DIALOG,
TIMEOUT_IDE_LOAD,
@@ -69,7 +70,7 @@ def _log(message: str) -> None:
"""Emit a timestamped progress line so a long deploy step is not mistaken
for a hang. Visible under ``pytest -s`` / ``--verbose``.
"""
- print(f" [{time.strftime('%H:%M:%S')}] vip-publish: {message}", flush=True)
+ info(f" [{time.strftime('%H:%M:%S')}] vip-publish: {message}")
def _build_deploy_script(
diff --git a/website/src/pages/guide.astro b/website/src/pages/guide.astro
index 3bcaa67dc..047a8f8bb 100644
--- a/website/src/pages/guide.astro
+++ b/website/src/pages/guide.astro
@@ -291,6 +291,9 @@ vip verify --connect-url https://connect.example.com -- -x --tb=long--verbose for detailed output, including full
tracebacks, authentication progress, and IdP login steps. This is
especially helpful when diagnosing headless auth or MFA issues.
+ To hide progress messages instead, put -q before the
+ subcommand (vip -q verify); -q wins if you
+ also pass --verbose.
vip verify --connect-url https://connect.example.com --headless-auth --verbose