|
1 | 1 | import os |
2 | 2 | import re |
3 | | -import shutil |
4 | 3 | import subprocess |
5 | 4 | from pathlib import Path |
6 | 5 |
|
@@ -373,44 +372,23 @@ def test_copy_examples_force(example_cases, expected_paths, force): |
373 | 372 |
|
374 | 373 | @pytest.mark.parametrize("packs_to_install,expected", install_params) |
375 | 374 | def test_print_packs_and_examples( |
376 | | - packs_to_install, expected, example_cases, capsys |
| 375 | + packs_to_install, expected, example_cases, capsys, conda_env |
377 | 376 | ): |
378 | | - case5dir = example_cases / "case5" |
379 | | - env_dir = case5dir / "fake_env" |
380 | | - req_dir = case5dir / "requirements" / "packs" |
381 | | - # Handle Windows path format |
382 | | - env_dir_str = env_dir.as_posix() |
| 377 | + env_dir_str = Path(conda_env).as_posix() |
383 | 378 | shell = os.name == "nt" |
384 | | - try: |
| 379 | + req_dir = example_cases / "case5" / "requirements" / "packs" |
| 380 | + for pack in packs_to_install: |
| 381 | + req_file = (req_dir / f"{pack}.txt").as_posix() |
385 | 382 | subprocess.run( |
386 | | - ["conda", "create", "-y", "-p", env_dir_str], |
| 383 | + ["conda", "install", "-y", "--file", req_file, "-p", env_dir_str], |
387 | 384 | check=True, |
388 | 385 | capture_output=True, |
389 | 386 | text=True, |
390 | 387 | shell=shell, |
391 | 388 | ) |
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) |
| 389 | + pm = PacksManager(root_path=example_cases / "case5") |
| 390 | + pm.print_packs() |
| 391 | + pm.print_examples() |
| 392 | + captured = capsys.readouterr() |
| 393 | + actual = captured.out |
| 394 | + assert actual.strip() == expected.strip() |
0 commit comments