@@ -222,15 +222,22 @@ def test_resolves_symlink_before_checking_install_dir(
222222
223223
224224class TestWindowsUpdateCommand :
225- def _command (self , install , elevated = True , runner = None , downloader = None ):
225+ def _command (
226+ self ,
227+ install ,
228+ elevated = True ,
229+ runner = None ,
230+ downloader = None ,
231+ powershell_path = 'powershell.exe' ,
232+ ):
226233 return WindowsUpdateCommand (
227234 mock_session (),
228235 source = 'exe' ,
229236 install_metadata = install ,
230237 downloader = downloader or mock .Mock (),
231238 is_elevated = elevated ,
232239 runner = runner or mock .Mock (),
233- powershell_path = 'powershell.exe' ,
240+ powershell_path = powershell_path ,
234241 )
235242
236243 def _run (self , install , color = 'auto' , ** kwargs ):
@@ -275,6 +282,46 @@ def test_wrapper_sets_no_color_when_color_off(self):
275282
276283 assert 'set NO_COLOR=1' in wrapper
277284
285+ def test_wrapper_clears_psmodulepath (self ):
286+ _ , wrapper = self ._run (USER_INSTALL )
287+
288+ assert 'set PSModulePath=\n ' in wrapper
289+
290+ def test_prefers_windows_powershell_when_available (self , monkeypatch ):
291+ def which (name ):
292+ return {
293+ 'powershell' : 'C:\\ powershell.exe' ,
294+ 'pwsh' : 'C:\\ pwsh.exe' ,
295+ }.get (name )
296+
297+ monkeypatch .setattr (update_module .shutil , 'which' , which )
298+
299+ _ , wrapper = self ._run (USER_INSTALL , powershell_path = None )
300+
301+ assert '"C:\\ powershell.exe" -NoProfile' in wrapper
302+
303+ def test_falls_back_to_pwsh_when_windows_powershell_missing (
304+ self , monkeypatch
305+ ):
306+ def which (name ):
307+ return 'C:\\ pwsh.exe' if name == 'pwsh' else None
308+
309+ monkeypatch .setattr (update_module .shutil , 'which' , which )
310+
311+ _ , wrapper = self ._run (USER_INSTALL , powershell_path = None )
312+
313+ assert '"C:\\ pwsh.exe" -NoProfile' in wrapper
314+
315+ def test_raises_when_no_powershell_found (self , monkeypatch ):
316+ def which (name ):
317+ return None
318+
319+ monkeypatch .setattr (update_module .shutil , 'which' , which )
320+ command = self ._command (USER_INSTALL , powershell_path = None )
321+
322+ with pytest .raises (UpdateError , match = 'Neither powershell' ):
323+ command ([], global_args ())
324+
278325 def test_system_install_requires_elevation (self ):
279326 runner = mock .Mock ()
280327 command = self ._command (SYSTEM_INSTALL , elevated = False , runner = runner )
0 commit comments