MCPcopy Index your code
hub / github.com/python/cpython / do_test_with_pip

Method do_test_with_pip

Lib/test/test_venv.py:939–1033  ·  view source on GitHub ↗
(self, system_site_packages)

Source from the content-addressed store, hash-verified

937 self.assertTrue(os.path.exists(os.devnull))
938
939 def do_test_with_pip(self, system_site_packages):
940 rmtree(self.env_dir)
941 with EnvironmentVarGuard() as envvars:
942 # pip's cross-version compatibility may trigger deprecation
943 # warnings in current versions of Python. Ensure related
944 # environment settings don't cause venv to fail.
945 envvars["PYTHONWARNINGS"] = "ignore"
946 # ensurepip is different enough from a normal pip invocation
947 # that we want to ensure it ignores the normal pip environment
948 # variable settings. We set PIP_NO_INSTALL here specifically
949 # to check that ensurepip (and hence venv) ignores it.
950 # See http://bugs.python.org/issue19734
951 envvars["PIP_NO_INSTALL"] = "1"
952 # Also check that we ignore the pip configuration file
953 # See http://bugs.python.org/issue20053
954 with tempfile.TemporaryDirectory() as home_dir:
955 envvars["HOME"] = home_dir
956 bad_config = "[global]\nno-install=1"
957 # Write to both config file names on all platforms to reduce
958 # cross-platform variation in test code behaviour
959 win_location = ("pip", "pip.ini")
960 posix_location = (".pip", "pip.conf")
961 # Skips win_location due to http://bugs.python.org/issue20541
962 for dirname, fname in (posix_location,):
963 dirpath = os.path.join(home_dir, dirname)
964 os.mkdir(dirpath)
965 fpath = os.path.join(dirpath, fname)
966 with open(fpath, 'w') as f:
967 f.write(bad_config)
968
969 # Actually run the create command with all that unhelpful
970 # config in place to ensure we ignore it
971 with self.nicer_error():
972 self.run_with_capture(venv.create, self.env_dir,
973 system_site_packages=system_site_packages,
974 with_pip=True)
975 # Ensure pip is available in the virtual environment
976 # Ignore DeprecationWarning since pip code is not part of Python
977 out, err = check_output([self.envpy(real_env_dir=True),
978 '-W', 'ignore::DeprecationWarning',
979 '-W', 'ignore::ImportWarning', '-I',
980 '-m', 'pip', '--version'])
981 # We force everything to text, so unittest gives the detailed diff
982 # if we get unexpected results
983 err = err.decode("latin-1") # Force to text, prevent decoding errors
984 self.assertEqual(err, "")
985 out = out.decode("latin-1") # Force to text, prevent decoding errors
986 expected_version = "pip {}".format(ensurepip.version())
987 self.assertStartsWith(out, expected_version)
988 env_dir = os.fsencode(self.env_dir).decode("latin-1")
989 self.assertIn(env_dir, out)
990
991 # http://bugs.python.org/issue19728
992 # Check the private uninstall command provided for the Windows
993 # installers works (at least in a virtual environment)
994 with EnvironmentVarGuard() as envvars:
995 with self.nicer_error():
996 # It seems ensurepip._uninstall calls subprocesses which do not

Callers 1

test_with_pipMethod · 0.95

Calls 15

nicer_errorMethod · 0.95
rmtreeFunction · 0.90
EnvironmentVarGuardClass · 0.90
run_with_captureMethod · 0.80
envpyMethod · 0.80
assertStartsWithMethod · 0.80
assertInMethod · 0.80
check_outputFunction · 0.70
openFunction · 0.50
joinMethod · 0.45
mkdirMethod · 0.45

Tested by

no test coverage detected