diff --git a/src/pipdeptree/__main__.py b/src/pipdeptree/__main__.py index d5881a0..0edf246 100644 --- a/src/pipdeptree/__main__.py +++ b/src/pipdeptree/__main__.py @@ -26,7 +26,9 @@ def main(args: Sequence[str] | None = None) -> None | int: warning_printer.warning_type = options.warn if options.python == "auto": - options.python = detect_active_interpreter() + resolved_path = detect_active_interpreter() + options.python = resolved_path + print(f"(resolved python: {resolved_path})", file=sys.stderr) # noqa: T201 pkgs = get_installed_distributions( interpreter=options.python, local_only=options.local_only, user_only=options.user_only diff --git a/tests/test_pipdeptree.py b/tests/test_pipdeptree.py index 967b71c..4a5472a 100644 --- a/tests/test_pipdeptree.py +++ b/tests/test_pipdeptree.py @@ -1,11 +1,17 @@ from __future__ import annotations import sys -from subprocess import check_call # noqa: S404 +from subprocess import CompletedProcess, check_call # noqa: S404 from typing import TYPE_CHECKING +from pipdeptree.__main__ import main + if TYPE_CHECKING: + from pathlib import Path + + import pytest from pytest_console_scripts import ScriptRunner + from pytest_mock import MockFixture def test_main() -> None: @@ -15,3 +21,21 @@ def test_main() -> None: def test_console(script_runner: ScriptRunner) -> None: result = script_runner.run(["pipdeptree", "--help"]) assert result.success + + +def test_main_log_resolved(tmp_path: Path, mocker: MockFixture, capsys: pytest.CaptureFixture[str]) -> None: + mocker.patch("sys.argv", ["", "--python", "auto"]) + mocker.patch("pipdeptree.__main__.detect_active_interpreter", return_value=str(tmp_path)) + mock_subprocess_run = mocker.patch("subprocess.run") + valid_sys_path = str([str(tmp_path)]) + mock_subprocess_run.return_value = CompletedProcess( + args=["python", "-c", "import sys; print(sys.path)"], + returncode=0, + stdout=valid_sys_path, + stderr="", + ) + + main() + + captured = capsys.readouterr() + assert captured.err.startswith(f"(resolved python: {tmp_path!s}")