Skip to content

Commit a472244

Browse files
authored
tests: add test.support.venv.VirtualEnvironmentMixin (python#129461)
1 parent a549f43 commit a472244

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Lib/test/support/venv.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import sysconfig
88
import tempfile
9+
import unittest
910
import venv
1011

1112

@@ -68,3 +69,14 @@ def run(self, *args, **subprocess_args):
6869
raise
6970
else:
7071
return result
72+
73+
74+
class VirtualEnvironmentMixin:
75+
def venv(self, name=None, **venv_create_args):
76+
venv_name = self.id()
77+
if name:
78+
venv_name += f'-{name}'
79+
return VirtualEnvironment.from_tmpdir(
80+
prefix=f'{venv_name}-venv-',
81+
**venv_create_args,
82+
)

Lib/test/test_sysconfig.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from test.support.import_helper import import_module
2121
from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink,
2222
change_cwd)
23-
from test.support.venv import VirtualEnvironment
23+
from test.support.venv import VirtualEnvironmentMixin
2424

2525
import sysconfig
2626
from sysconfig import (get_paths, get_platform, get_config_vars,
@@ -37,7 +37,7 @@
3737
HAS_USER_BASE = sysconfig._HAS_USER_BASE
3838

3939

40-
class TestSysConfig(unittest.TestCase):
40+
class TestSysConfig(unittest.TestCase, VirtualEnvironmentMixin):
4141

4242
def setUp(self):
4343
super(TestSysConfig, self).setUp()
@@ -111,13 +111,6 @@ def _cleanup_testfn(self):
111111
elif os.path.isdir(path):
112112
shutil.rmtree(path)
113113

114-
def venv(self, **venv_create_args):
115-
return VirtualEnvironment.from_tmpdir(
116-
prefix=f'{self.id()}-venv-',
117-
**venv_create_args,
118-
)
119-
120-
121114
def test_get_path_names(self):
122115
self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)
123116

0 commit comments

Comments
 (0)