diff --git a/src/spikeinterface/sorters/tests/test_runsorter.py b/src/spikeinterface/sorters/tests/test_runsorter.py index df7389e844..f55736f8c3 100644 --- a/src/spikeinterface/sorters/tests/test_runsorter.py +++ b/src/spikeinterface/sorters/tests/test_runsorter.py @@ -10,25 +10,28 @@ ON_GITHUB = bool(os.getenv("GITHUB_ACTIONS")) +# +# if hasattr(pytest, "global_test_folder"): +# cache_folder = pytest.global_test_folder / "sorters" +# else: +# cache_folder = Path("cache_folder") / "sorters" +# +# rec_folder = cache_folder / "recording" -if hasattr(pytest, "global_test_folder"): - cache_folder = pytest.global_test_folder / "sorters" -else: - cache_folder = Path("cache_folder") / "sorters" - -rec_folder = cache_folder / "recording" - - -def setup_module(): +import pytest +@pytest.fixture(scope='function') +def setup_module(tmp_path): + rec_folder = tmp_path / "recording" if rec_folder.exists(): shutil.rmtree(rec_folder) recording, sorting_gt = generate_ground_truth_recording(num_channels=8, durations=[10.0], seed=2205) recording = recording.save(folder=rec_folder) + yield [tmp_path, rec_folder] - -def test_run_sorter_local(): +def test_run_sorter_local(setup_module): # local_path = download_dataset(remote_path="mearec/mearec_test_10s.h5") # recording, sorting_true = read_mearec(local_path) + tmp_path, rec_folder = setup_module recording = load_extractor(rec_folder) sorter_params = {"detect_threshold": 4.9} @@ -36,7 +39,7 @@ def test_run_sorter_local(): sorting = run_sorter( "tridesclous", recording, - output_folder=cache_folder / "sorting_tdc_local", + output_folder=tmp_path / "sorting_tdc_local", remove_existing_folder=True, delete_output_folder=False, verbose=True, @@ -48,9 +51,10 @@ def test_run_sorter_local(): @pytest.mark.skipif(ON_GITHUB, reason="Docker tests don't run on github: test locally") -def test_run_sorter_docker(): +def test_run_sorter_docker(setup_module): # mearec_filename = download_dataset(remote_path="mearec/mearec_test_10s.h5", unlock=True) # recording, sorting_true = read_mearec(mearec_filename) + tmp_path, rec_folder = setup_module recording = load_extractor(rec_folder) @@ -60,7 +64,7 @@ def test_run_sorter_docker(): for installation_mode in ("dev", "pypi", "github"): print(f"\nTest with installation_mode {installation_mode}") - output_folder = cache_folder / f"sorting_tdc_docker_{installation_mode}" + output_folder = tmp_path / f"sorting_tdc_docker_{installation_mode}" sorting = run_sorter( "tridesclous", @@ -82,9 +86,10 @@ def test_run_sorter_docker(): @pytest.mark.skipif(ON_GITHUB, reason="Singularity tests don't run on github: test it locally") -def test_run_sorter_singularity(): +def test_run_sorter_singularity(setup_module): # mearec_filename = download_dataset(remote_path="mearec/mearec_test_10s.h5", unlock=True) # recording, sorting_true = read_mearec(mearec_filename) + tmp_path, rec_folder = setup_module # use an output folder outside of the package. otherwise dev mode will not work singularity_cache_folder = Path(si.__file__).parents[3] / "sandbox"