Skip to content

Commit 12b52e7

Browse files
pradyunsgichard26
andcommitted
Enable verbose logging with --debug (pypa#12710)
This helps ensure that all relevant context is presented when a failure happens and diagnosis is being done through the use of `--debug`. Co-authored-by: Pradyun Gedam <[email protected]> Co-authored-by: Richard Si <[email protected]>
1 parent 48d8d1d commit 12b52e7

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

news/12710.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Using ``--debug`` also enables verbose logging.

src/pip/_internal/cli/base_command.py

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def _main(self, args: List[str]) -> int:
172172

173173
# Set verbosity so that it can be used elsewhere.
174174
self.verbosity = options.verbose - options.quiet
175+
if options.debug_mode:
176+
self.verbosity = 2
175177

176178
reconfigure(no_color=options.no_color)
177179
level_number = setup_logging(

tests/unit/test_base_command.py

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ def test_handle_pip_version_check_called(mock_handle_version_check: Mock) -> Non
107107
mock_handle_version_check.assert_called_once()
108108

109109

110+
def test_debug_enables_verbose_logs() -> None:
111+
cmd = FakeCommand()
112+
cmd.main(["fake", "--debug"])
113+
assert cmd.verbosity >= 2
114+
115+
110116
def test_log_command_success(fixed_time: None, tmpdir: Path) -> None:
111117
"""Test the --log option logs when command succeeds."""
112118
cmd = FakeCommand()

0 commit comments

Comments
 (0)