diff --git a/bluecellulab/importer.py b/bluecellulab/importer.py index 2f76a61c..ba24d5ff 100644 --- a/bluecellulab/importer.py +++ b/bluecellulab/importer.py @@ -75,6 +75,7 @@ def print_header(neuron: ModuleType, mod_lib_path: str) -> None: @run_once def _load_hoc_and_mod_files() -> None: """Import hoc and mod files.""" + neuron.load_mechanisms(".") logger.info("Loading the mod files.") mod_lib_paths = import_mod_lib(neuron) logger.info("Loading the hoc files.") diff --git a/tests/test_import_directory.py b/tests/test_import_directory.py new file mode 100644 index 00000000..ad034a7b --- /dev/null +++ b/tests/test_import_directory.py @@ -0,0 +1,18 @@ +"""This test file is to ensure mechanisms are loaded where Cell is created.""" +import os +from pathlib import Path + + +def test_import_vs_first_call_neuron_mechanisms_dir(): + """Test if the neuron import directory is set at import or at the first call.""" + os.chdir("tests") # there are no mechanisms here + + # intentionally imported in the directory without compiled mechanisms + from bluecellulab import Cell # noqa: E402 + + examples_dir = Path(__file__).resolve().parent / "examples" + + os.chdir("..") # mechanisms at .. should be loaded + hoc_path = examples_dir / "bpo_cell" / "0_cADpyr_L5TPC_a6e707a_1_sNone.hoc" + morph_path = examples_dir / "bpo_cell" / "C060114A5.asc" + _ = Cell(hoc_path, morph_path, template_format="bluepyopt")