Skip to content

Commit 202c472

Browse files
authored
Error when frameworks installation script fails (#685)
* Error when frameworks installation script fails * Fix loading of frameworks for tests * Do not force usage of -e
1 parent e8a0672 commit 202c472

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

amlb/benchmark.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,17 @@ def setup(self, mode: SetupMode):
193193
self._mark_setup_start()
194194

195195
if hasattr(self.framework_module, "setup"):
196-
self.framework_module.setup(
197-
*self.framework_def.setup_args,
198-
_shell_=False, # prevents #arg from being interpreted as comment
199-
_live_output_=rconfig().setup.live_output,
200-
_activity_timeout_=rconfig().setup.activity_timeout,
201-
)
196+
try:
197+
self.framework_module.setup(
198+
*self.framework_def.setup_args,
199+
_shell_=False, # prevents #arg from being interpreted as comment
200+
_live_output_=rconfig().setup.live_output,
201+
_activity_timeout_=rconfig().setup.activity_timeout,
202+
)
203+
except Exception as e:
204+
raise JobError(
205+
f"Setup of framework {self.framework_name} failed."
206+
) from e
202207

203208
if self.framework_def.setup_script is not None:
204209
run_script(

tests/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ def load_default_resources(tmp_path):
1212
os.path.join(default_dirs.root_dir, "resources", "config.yaml")
1313
)
1414
config_default_dirs = default_dirs
15+
config_test = Namespace(
16+
frameworks=Namespace(
17+
definition_file=[
18+
"{root}/resources/frameworks.yaml",
19+
"{root}/tests/resources/frameworks.yaml",
20+
]
21+
)
22+
)
1523
# allowing config override from user_dir: useful to define custom benchmarks and frameworks for example.
1624
config_user = Namespace()
1725
# config listing properties set by command line
@@ -30,7 +38,7 @@ def load_default_resources(tmp_path):
3038
config_args = Namespace({k: v for k, v in config_args if v is not None})
3139
# merging all configuration files and saving to the global variable
3240
resources.from_configs(
33-
config_default, config_default_dirs, config_user, config_args
41+
config_default, config_test, config_default_dirs, config_user, config_args
3442
)
3543

3644

tests/resources/frameworks.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
setup_fail:
2+
description: "used for tests"
3+
module: tests.resources.frameworks.setup_fail
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from amlb.utils import call_script_in_same_dir
2+
3+
4+
def setup(*args, **kwargs):
5+
call_script_in_same_dir(__file__, "setup.sh", *args, **kwargs)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
command_that_fails
5+
6+
echo "Command that succeeds"

tests/unit/amlb/benchmarks/test_benchmark.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from pathlib import Path
2+
from subprocess import SubprocessError
23

34
import pytest
45

56
from amlb import Benchmark, SetupMode, resources, DockerBenchmark, SingularityBenchmark
7+
from amlb.job import JobError
68
from amlb.utils import Namespace
79

810

@@ -112,3 +114,20 @@ def test_singularity_image_name_as_docker(
112114
as_docker_image=True,
113115
)
114116
assert result == expected
117+
118+
119+
def test_benchmark_setup_errors_if_framework_does_not_install(
120+
load_default_resources,
121+
) -> None:
122+
benchmark = Benchmark(
123+
framework_name="setup_fail",
124+
benchmark_name="test",
125+
constraint_name="test",
126+
job_history=None,
127+
)
128+
129+
with pytest.raises(JobError) as exc_info:
130+
benchmark.setup(SetupMode.force)
131+
assert "setup" in str(exc_info.value)
132+
assert isinstance(exc_info.value.__cause__, SubprocessError)
133+
assert "command_that_fails" in exc_info.value.__cause__.stderr

0 commit comments

Comments
 (0)