diff options
author | Steve Dower <steve.dower@microsoft.com> | 2019-03-21 10:04:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-21 10:04:21 -0700 |
commit | 8bba81fd55873148c65b7d0e6a6effbd63048c76 (patch) | |
tree | dcf33cf11d17ac5d0c3a157ef682c7d72a8a9943 /Lib/test/test_venv.py | |
parent | 7ee88bf3e59493137a775368165c5c5fe1ed7f46 (diff) | |
download | cpython-git-8bba81fd55873148c65b7d0e6a6effbd63048c76.tar.gz |
bpo-35978: Correctly skips venv tests in venvs (GH-12220)
Also fixes venvs from the build directory on Windows.
Diffstat (limited to 'Lib/test/test_venv.py')
-rw-r--r-- | Lib/test/test_venv.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 0b2c7a0258..6822d567e4 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -24,8 +24,12 @@ try: 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, @@ -126,7 +130,7 @@ class BasicTest(BaseTest): self.assertEqual(context.prompt, '(My prompt) ') self.assertIn("prompt = 'My prompt'\n", data) - @skipInVenv + @requireVenvCreate def test_prefixes(self): """ Test that the prefix values are as expected. @@ -262,7 +266,7 @@ class BasicTest(BaseTest): # 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. @@ -306,6 +310,7 @@ class BasicTest(BaseTest): ) self.assertEqual(out.strip(), '0') + @requireVenvCreate def test_multiprocessing(self): """ Test that the multiprocessing is able to spawn. @@ -319,7 +324,7 @@ class BasicTest(BaseTest): '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): |