@@ -15,16 +15,19 @@ type PackageManagerId = `${string}:${string}`;
1515interface PackageManagerProfile {
1616 environmentManagerId : string ;
1717 name : string ;
18+ packageName : string ;
1819 packageManagerId : PackageManagerId ;
1920 projectDirectory : string ;
2021 prerequisite ( api : PythonEnvironmentApi ) : Promise < boolean > ;
22+ reuseExistingEnvironment ?: boolean ;
2123 supportsVersionLookup ( packages : Package [ ] ) : boolean ;
2224}
2325
2426const profiles : PackageManagerProfile [ ] = [
2527 {
2628 environmentManagerId : VENV_MANAGER_ID ,
2729 name : 'Pip' ,
30+ packageName : 'requests' ,
2831 packageManagerId : DEFAULT_PACKAGE_MANAGER_ID ,
2932 projectDirectory : 'pip' ,
3033 prerequisite : async ( api ) =>
@@ -37,6 +40,7 @@ const profiles: PackageManagerProfile[] = [
3740 {
3841 environmentManagerId : CONDA_MANAGER_ID ,
3942 name : 'Conda' ,
43+ packageName : 'flask' ,
4044 packageManagerId : CONDA_MANAGER_ID ,
4145 projectDirectory : 'conda' ,
4246 prerequisite : async ( ) => {
@@ -47,6 +51,7 @@ const profiles: PackageManagerProfile[] = [
4751 return false ;
4852 }
4953 } ,
54+ reuseExistingEnvironment : true ,
5055 supportsVersionLookup : ( ) => true ,
5156 } ,
5257] ;
@@ -105,6 +110,7 @@ for (const profile of profiles) {
105110 let previousAlwaysUseUv : boolean | undefined ;
106111 let previousPythonProjects : PythonProjectSettings [ ] | undefined ;
107112 let alwaysUseUvUpdated = false ;
113+ let createdEnvironment = false ;
108114 let pythonProjectsUpdated = false ;
109115 suiteSetup ( async function ( ) {
110116 if ( process . env . VSC_PYTHON_PACKAGE_NETWORK_TEST !== '1' ) {
@@ -127,8 +133,8 @@ for (const profile of profiles) {
127133 const config = vscode . workspace . getConfiguration ( 'python-envs' , workspaceUri ) ;
128134
129135 if ( profile . packageManagerId === DEFAULT_PACKAGE_MANAGER_ID ) {
130- previousAlwaysUseUv = config . inspect < boolean > ( 'alwaysUseUv' ) ?. workspaceFolderValue ;
131- await config . update ( 'alwaysUseUv' , false , vscode . ConfigurationTarget . WorkspaceFolder ) ;
136+ previousAlwaysUseUv = config . inspect < boolean > ( 'alwaysUseUv' ) ?. globalValue ;
137+ await config . update ( 'alwaysUseUv' , false , vscode . ConfigurationTarget . Global ) ;
132138 alwaysUseUvUpdated = true ;
133139 }
134140
@@ -137,6 +143,15 @@ for (const profile of profiles) {
137143 return ;
138144 }
139145
146+ if ( profile . reuseExistingEnvironment ) {
147+ await api . refreshEnvironments ( undefined ) ;
148+ environment = ( await api . getEnvironments ( 'global' ) ) . find (
149+ ( candidate ) => candidate . envId . managerId === profile . environmentManagerId ,
150+ ) ;
151+ assert . ok ( environment , `No existing ${ profile . name } environment is available` ) ;
152+ return ;
153+ }
154+
140155 const projectUri = vscode . Uri . joinPath (
141156 workspaceUri ,
142157 `.package-manager-test-${ profile . projectDirectory } -${ process . pid } ` ,
@@ -172,6 +187,7 @@ for (const profile of profiles) {
172187 await api . refreshEnvironments ( projectUri ) ;
173188
174189 environment = await api . createEnvironment ( projectUri , { quickCreate : true } ) ;
190+ createdEnvironment = environment !== undefined ;
175191 assert . ok ( environment , `${ profile . name } failed to create an environment after prerequisites passed` ) ;
176192 assert . strictEqual (
177193 environment . envId . managerId ,
@@ -181,7 +197,7 @@ for (const profile of profiles) {
181197 } ) ;
182198
183199 test ( `${ profile . name } Package Manager should install, list, and uninstall a package` , async ( ) => {
184- const packageName = 'requests' ;
200+ const packageName = profile . packageName ;
185201 const baseline = await api . getPackages ( environment ! , { skipCache : true } ) ;
186202 assert . ok ( baseline , 'Unable to list packages before installation' ) ;
187203 const wasInstalled = baseline . some ( ( pkg ) => pkg . name . toLowerCase ( ) === packageName ) ;
@@ -223,14 +239,14 @@ for (const profile of profiles) {
223239 return ;
224240 }
225241
226- const versions = await api . getPackageAvailableVersions ( environment ! , 'requests' ) ;
242+ const versions = await api . getPackageAvailableVersions ( environment ! , profile . packageName ) ;
227243 assert . ok ( versions , `${ profile . name } unexpectedly failed to retrieve package versions` ) ;
228244 assert . ok ( versions . length > 0 , 'No package versions available' ) ;
229245 } ) ;
230246
231247 suiteTeardown ( async ( ) => {
232248 try {
233- if ( environment ) {
249+ if ( environment && createdEnvironment ) {
234250 const environmentPath = environment . environmentPath ;
235251 await api . removeEnvironment ( environment , { runHeadless : true } ) ;
236252 await assert . rejects (
@@ -270,7 +286,7 @@ for (const profile of profiles) {
270286 await config . update (
271287 'alwaysUseUv' ,
272288 previousAlwaysUseUv ,
273- vscode . ConfigurationTarget . WorkspaceFolder ,
289+ vscode . ConfigurationTarget . Global ,
274290 ) ;
275291 }
276292 } finally {
0 commit comments