1
+ import os
1
2
from typing import Callable , List
2
3
from unittest import mock
3
4
@@ -104,6 +105,10 @@ def test_index_group_handle_pip_version_check(
104
105
options .disable_pip_version_check = disable_pip_version_check
105
106
options .no_index = no_index
106
107
108
+ # See test test_list_pip_version_check() below.
109
+ if command_name == "list" :
110
+ expected_called = False
111
+
107
112
command .handle_pip_version_check (options )
108
113
if expected_called :
109
114
mock_version_check .assert_called_once ()
@@ -120,3 +125,20 @@ def is_requirement_command(command: Command) -> bool:
120
125
return isinstance (command , RequirementCommand )
121
126
122
127
check_commands (is_requirement_command , ["download" , "install" , "wheel" ])
128
+
129
+
130
+ @pytest .mark .parametrize ("flag" , ["" , "--outdated" , "--uptodate" ])
131
+ @mock .patch ("pip._internal.cli.req_command.pip_self_version_check" )
132
+ @mock .patch .dict (os .environ , {"PIP_DISABLE_PIP_VERSION_CHECK" : "no" })
133
+ def test_list_pip_version_check (version_check_mock : mock .Mock , flag : str ) -> None :
134
+ """
135
+ Ensure that pip list doesn't perform a version self-check unless given
136
+ --outdated or --uptodate (as they require hitting the network anyway).
137
+ """
138
+ command = create_command ("list" )
139
+ command .run = lambda * args , ** kwargs : 0 # type: ignore[method-assign]
140
+ command .main ([flag ])
141
+ if flag != "" :
142
+ version_check_mock .assert_called_once ()
143
+ else :
144
+ version_check_mock .assert_not_called ()
0 commit comments