@@ -301,16 +301,35 @@ def test_with_pip(self):
301301 # that we want to ensure it ignores the normal pip environment
302302 # variable settings. We set PIP_NO_INSTALL here specifically
303303 # to check that ensurepip (and hence venv) ignores it.
304- # See http://bugs.python.org/issue19734 for details
304+ # See http://bugs.python.org/issue19734
305305 envvars ["PIP_NO_INSTALL" ] = "1"
306- try :
307- self .run_with_capture (venv .create , self .env_dir , with_pip = True )
308- except subprocess .CalledProcessError as exc :
309- # The output this produces can be a little hard to read, but
310- # least it has all the details
311- details = exc .output .decode (errors = "replace" )
312- msg = "{}\n \n **Subprocess Output**\n {}" .format (exc , details )
313- self .fail (msg )
306+ # Also check that we ignore the pip configuration file
307+ # See http://bugs.python.org/issue20053
308+ with tempfile .TemporaryDirectory () as home_dir :
309+ envvars ["HOME" ] = home_dir
310+ bad_config = "[global]\n no-install=1"
311+ # Write to both config file names on all platforms to reduce
312+ # cross-platform variation in test code behaviour
313+ win_location = ("pip" , "pip.ini" )
314+ posix_location = (".pip" , "pip.conf" )
315+ for dirname , fname in (win_location , posix_location ):
316+ dirpath = os .path .join (home_dir , dirname )
317+ os .mkdir (dirpath )
318+ fpath = os .path .join (dirpath , fname )
319+ with open (fpath , 'w' ) as f :
320+ f .write (bad_config )
321+
322+ # Actually run the create command with all that unhelpful
323+ # config in place to ensure we ignore it
324+ try :
325+ self .run_with_capture (venv .create , self .env_dir ,
326+ with_pip = True )
327+ except subprocess .CalledProcessError as exc :
328+ # The output this produces can be a little hard to read,
329+ # but at least it has all the details
330+ details = exc .output .decode (errors = "replace" )
331+ msg = "{}\n \n **Subprocess Output**\n {}"
332+ self .fail (msg .format (exc , details ))
314333 # Ensure pip is available in the virtual environment
315334 envpy = os .path .join (os .path .realpath (self .env_dir ), self .bindir , self .exe )
316335 cmd = [envpy , '-Im' , 'pip' , '--version' ]
0 commit comments