[3.7] bpo-35978: Correctly skips venv tests in venvs (GH-12220) by miss-islington · Pull Request #12485 · python/cpython

Expand Up @@ -24,8 +24,12 @@ except ImportError: ctypes = None
skipInVenv = unittest.skipIf(sys.prefix != sys.base_prefix, 'Test not appropriate in a venv') # Platforms that set sys._base_executable can create venvs from within # another venv, so no need to skip tests that require venv.create(). requireVenvCreate = unittest.skipUnless( hasattr(sys, '_base_executable') or sys.prefix == sys.base_prefix, 'cannot run venv.create from within a venv on this platform')
def check_output(cmd, encoding=None): p = subprocess.Popen(cmd, Expand Down Expand Up @@ -118,7 +122,7 @@ def test_prompt(self): context = builder.ensure_directories(self.env_dir) self.assertEqual(context.prompt, '(My prompt) ')
@skipInVenv @requireVenvCreate def test_prefixes(self): """ Test that the prefix values are as expected. Expand Down Expand Up @@ -254,7 +258,7 @@ def test_symlinking(self): # run the test, the pyvenv.cfg in the venv created in the test will # point to the venv being used to run the test, and we lose the link # to the source build - so Python can't initialise properly. @skipInVenv @requireVenvCreate def test_executable(self): """ Test that the sys.executable value is as expected. Expand Down Expand Up @@ -298,6 +302,7 @@ def test_unicode_in_batch_file(self): ) self.assertEqual(out.strip(), '0')
@requireVenvCreate def test_multiprocessing(self): """ Test that the multiprocessing is able to spawn. Expand All @@ -311,7 +316,7 @@ def test_multiprocessing(self): 'print(Pool(1).apply_async("Python".lower).get(3))']) self.assertEqual(out.strip(), "python".encode())
@skipInVenv @requireVenvCreate class EnsurePipTest(BaseTest): """Test venv module installation of pip.""" def assert_pip_not_installed(self): Expand Down