]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
tests: add test.support.venv.VirtualEnvironmentMixin (#129461)
authorFilipe Laíns 🇵🇸 <lains@riseup.net>
Thu, 30 Jan 2025 03:32:24 +0000 (03:32 +0000)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2025 03:32:24 +0000 (03:32 +0000)
Lib/test/support/venv.py
Lib/test/test_sysconfig.py

index 78e6a51ec1815eed24042d103254e15d057e4f38..7bfb9e4f3c479f53b3c485da9295bb82635bd7d8 100644 (file)
@@ -6,6 +6,7 @@ import shlex
 import sys
 import sysconfig
 import tempfile
+import unittest
 import venv
 
 
@@ -68,3 +69,14 @@ class VirtualEnvironment:
             raise
         else:
             return result
+
+
+class VirtualEnvironmentMixin:
+    def venv(self, name=None, **venv_create_args):
+        venv_name = self.id()
+        if name:
+            venv_name += f'-{name}'
+        return VirtualEnvironment.from_tmpdir(
+            prefix=f'{venv_name}-venv-',
+            **venv_create_args,
+        )
index 3950d8888d4c8cf44c3c84536d7e32c4b1f5ed90..3738914cf17de8bd8d745cf5eadeaf0593f6beed 100644 (file)
@@ -20,7 +20,7 @@ from test.support import (
 from test.support.import_helper import import_module
 from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink,
                                     change_cwd)
-from test.support.venv import VirtualEnvironment
+from test.support.venv import VirtualEnvironmentMixin
 
 import sysconfig
 from sysconfig import (get_paths, get_platform, get_config_vars,
@@ -37,7 +37,7 @@ import _sysconfig
 HAS_USER_BASE = sysconfig._HAS_USER_BASE
 
 
-class TestSysConfig(unittest.TestCase):
+class TestSysConfig(unittest.TestCase, VirtualEnvironmentMixin):
 
     def setUp(self):
         super(TestSysConfig, self).setUp()
@@ -111,13 +111,6 @@ class TestSysConfig(unittest.TestCase):
         elif os.path.isdir(path):
             shutil.rmtree(path)
 
-    def venv(self, **venv_create_args):
-        return VirtualEnvironment.from_tmpdir(
-            prefix=f'{self.id()}-venv-',
-            **venv_create_args,
-        )
-
-
     def test_get_path_names(self):
         self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)