11import os
22import re
3+ import shutil
34import subprocess
45from pathlib import Path
56
@@ -350,12 +351,15 @@ def test_copy_examples_force(example_cases, expected_paths, force):
350351 # expected: print_info output showing packA installed but not packB
351352 ("packA" ,),
352353 """Installed Packs:
354+ ----------------
353355 packA
354356
355- Available Packs to Install:
357+ Available Packs:
358+ ----------------
356359 packB
357360
358361Examples:
362+ ---------
359363 packA:
360364 - ex1
361365 - ex2
@@ -368,31 +372,45 @@ def test_copy_examples_force(example_cases, expected_paths, force):
368372
369373
370374@pytest .mark .parametrize ("packs_to_install,expected" , install_params )
371- def test_print_info (packs_to_install , expected , example_cases , capsys ):
375+ def test_print_packs_and_examples (
376+ packs_to_install , expected , example_cases , capsys
377+ ):
372378 case5dir = example_cases / "case5"
373379 env_dir = case5dir / "fake_env"
374380 req_dir = case5dir / "requirements" / "packs"
375381 # Handle Windows path format
376382 env_dir_str = env_dir .as_posix ()
377383 shell = os .name == "nt"
378- subprocess .run (
379- ["conda" , "create" , "-y" , "-p" , env_dir_str ],
380- check = True ,
381- capture_output = True ,
382- text = True ,
383- shell = shell ,
384- )
385- for pack in packs_to_install :
386- req_file = (req_dir / f"{ pack } .txt" ).as_posix ()
384+ try :
387385 subprocess .run (
388- ["conda" , "install " , "-y" , "--file" , req_file , "-p" , env_dir_str ],
386+ ["conda" , "create " , "-y" , "-p" , env_dir_str ],
389387 check = True ,
390388 capture_output = True ,
391389 text = True ,
392390 shell = shell ,
393391 )
394- pm = PacksManager (root_path = case5dir )
395- pm .print_info ()
396- captured = capsys .readouterr ()
397- actual = captured .out
398- assert actual .strip () == expected .strip ()
392+ for pack in packs_to_install :
393+ req_file = (req_dir / f"{ pack } .txt" ).as_posix ()
394+ subprocess .run (
395+ [
396+ "conda" ,
397+ "install" ,
398+ "-y" ,
399+ "--file" ,
400+ req_file ,
401+ "-p" ,
402+ env_dir_str ,
403+ ],
404+ check = True ,
405+ capture_output = True ,
406+ text = True ,
407+ shell = shell ,
408+ )
409+ pm = PacksManager (root_path = case5dir )
410+ pm .print_packs ()
411+ pm .print_examples ()
412+ captured = capsys .readouterr ()
413+ actual = captured .out
414+ assert actual .strip () == expected .strip ()
415+ finally :
416+ shutil .rmtree (env_dir , ignore_errors = True )
0 commit comments