Skip to content

Commit 1e71c1d

Browse files
committed
raise exceptions instead of skipping, more defensively run scenario
1 parent f79e46c commit 1e71c1d

2 files changed

Lines changed: 44 additions & 52 deletions

File tree

tests/smoketests/sdk/test_async_benchmark.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def test_benchmark_from_existing(self, async_sdk_client: AsyncRunloopSDK)
3333
benchmarks = benchmarks_page.benchmarks
3434

3535
if not benchmarks:
36-
pytest.skip("No benchmarks available to test")
36+
raise Exception("No benchmarks available to test")
3737

3838
benchmark_data = benchmarks[0]
3939

@@ -69,9 +69,11 @@ async def test_benchmark_run_and_cancel(self, async_sdk_client: AsyncRunloopSDK)
6969
benchmarks = benchmarks_page.benchmarks
7070

7171
if not benchmarks:
72-
pytest.skip("No benchmarks available to test")
72+
raise Exception("No benchmarks available to test")
7373

7474
benchmark_data = benchmarks[0]
75+
if not benchmark_data.scenario_ids:
76+
raise Exception("No scenarios available to test")
7577

7678
# Create AsyncBenchmark wrapper
7779
benchmark = AsyncBenchmark(
@@ -81,14 +83,8 @@ async def test_benchmark_run_and_cancel(self, async_sdk_client: AsyncRunloopSDK)
8183

8284
# Start a run
8385
run = await benchmark.run(run_name="sdk-smoketest-async-benchmark-run")
84-
85-
# If the benchmark has scenarios, run one
86-
scenario_runs: list[AsyncScenarioRun] = []
87-
if benchmark_data.scenario_ids:
88-
scenario = async_sdk_client.scenario.from_id(benchmark_data.scenario_ids[0])
89-
scenario_runs.append(
90-
await scenario.run(benchmark_run_id=run.id, run_name="sdk-smoketest-async-benchmark-run-scenario")
91-
)
86+
scenario = async_sdk_client.scenario.from_id(benchmark_data.scenario_ids[0])
87+
scenario_run = None
9288

9389
try:
9490
assert isinstance(run, AsyncBenchmarkRun)
@@ -100,30 +96,30 @@ async def test_benchmark_run_and_cancel(self, async_sdk_client: AsyncRunloopSDK)
10096
assert info.id == run.id
10197
assert info.state in ["running", "completed", "canceled"]
10298

103-
bench_scenario_runs = await run.list_scenario_runs()
104-
assert isinstance(bench_scenario_runs, list)
105-
assert len(bench_scenario_runs) == len(scenario_runs)
106-
for bench_scenario_run in bench_scenario_runs:
107-
assert isinstance(bench_scenario_run, AsyncScenarioRun)
108-
assert bench_scenario_run.id == scenario_runs[0].id
109-
assert bench_scenario_run.devbox_id == scenario_runs[0].devbox_id
99+
# Start a scenario run
100+
scenario_run = await scenario.run(
101+
benchmark_run_id=run.id, run_name="sdk-smoketest-async-benchmark-run-scenario"
102+
)
103+
scenario_runs = await run.list_scenario_runs()
104+
assert isinstance(scenario_runs, list)
105+
assert len(scenario_runs) == 1
106+
assert isinstance(scenario_runs[0], AsyncScenarioRun)
107+
assert scenario_runs[0].id == scenario_run.id
108+
assert scenario_runs[0].devbox_id == scenario_run.devbox_id
110109

111-
# Cancel the scenario run
112-
scenario_result = await bench_scenario_run.cancel()
113-
assert scenario_result.state in ["canceled", "completed"]
110+
# Cancel the scenario run
111+
scenario_result = await scenario_run.cancel()
112+
assert scenario_result.state in ["canceled", "completed"]
114113

115114
# Cancel the benchmark run
116115
result = await run.cancel()
117116
assert result.state in ["canceled", "completed"]
118117

119118
except Exception:
120119
# Ensure cleanup on any error
121-
try:
122-
for scenario_run in scenario_runs:
123-
await async_sdk_client.api.scenarios.runs.cancel(scenario_run.id)
124-
await async_sdk_client.api.benchmarks.runs.cancel(run.id)
125-
except Exception:
126-
pass
120+
if scenario_run:
121+
await async_sdk_client.api.scenarios.runs.cancel(scenario_run.id)
122+
await async_sdk_client.api.benchmarks.runs.cancel(run.id)
127123
raise
128124

129125

@@ -144,7 +140,7 @@ async def test_list_runs(self, async_sdk_client: AsyncRunloopSDK) -> None:
144140
benchmarks = benchmarks_page.benchmarks
145141

146142
if not benchmarks:
147-
pytest.skip("No benchmarks available to test")
143+
raise Exception("No benchmarks available to test")
148144

149145
benchmark_data = benchmarks[0]
150146

tests/smoketests/sdk/test_benchmark.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_benchmark_from_existing(self, sdk_client: RunloopSDK) -> None:
3232
benchmarks = sdk_client.api.benchmarks.list_public(limit=1).benchmarks
3333

3434
if not benchmarks:
35-
pytest.skip("No benchmarks available to test")
35+
raise Exception("No benchmarks available to test")
3636

3737
benchmark_data = benchmarks[0]
3838

@@ -67,9 +67,11 @@ def test_benchmark_run_lifecycle(self, sdk_client: RunloopSDK) -> None:
6767
benchmarks = sdk_client.api.benchmarks.list_public(limit=1).benchmarks
6868

6969
if not benchmarks:
70-
pytest.skip("No benchmarks available to test")
70+
raise Exception("No benchmarks available to test")
7171

7272
benchmark_data = benchmarks[0]
73+
if not benchmark_data.scenario_ids:
74+
raise Exception("No scenarios available to test")
7375

7476
# Create Benchmark wrapper
7577
benchmark = Benchmark(
@@ -79,12 +81,8 @@ def test_benchmark_run_lifecycle(self, sdk_client: RunloopSDK) -> None:
7981

8082
# Start a run
8183
run = benchmark.run(run_name="sdk-smoketest-benchmark-run")
82-
83-
# If the benchmark has scenarios, run one
84-
scenario_runs: list[ScenarioRun] = []
85-
if benchmark_data.scenario_ids:
86-
scenario = sdk_client.scenario.from_id(benchmark_data.scenario_ids[0])
87-
scenario_runs.append(scenario.run(benchmark_run_id=run.id, run_name="sdk-smoketest-benchmark-run-scenario"))
84+
scenario = sdk_client.scenario.from_id(benchmark_data.scenario_ids[0])
85+
scenario_run = None
8886

8987
try:
9088
assert isinstance(run, BenchmarkRun)
@@ -96,30 +94,28 @@ def test_benchmark_run_lifecycle(self, sdk_client: RunloopSDK) -> None:
9694
assert info.id == run.id
9795
assert info.state in ["running", "completed", "canceled"]
9896

99-
bench_scenario_runs = run.list_scenario_runs()
100-
assert isinstance(bench_scenario_runs, list)
101-
assert len(bench_scenario_runs) == len(scenario_runs)
102-
for bench_scenario_run in bench_scenario_runs:
103-
assert isinstance(bench_scenario_run, ScenarioRun)
104-
assert bench_scenario_run.id == scenario_runs[0].id
105-
assert bench_scenario_run.devbox_id == scenario_runs[0].devbox_id
97+
# Start a scenario run
98+
scenario_run = scenario.run(benchmark_run_id=run.id, run_name="sdk-smoketest-benchmark-run-scenario")
99+
scenario_runs = run.list_scenario_runs()
100+
assert isinstance(scenario_runs, list)
101+
assert len(scenario_runs) == 1
102+
assert isinstance(scenario_runs[0], ScenarioRun)
103+
assert scenario_runs[0].id == scenario_run.id
104+
assert scenario_runs[0].devbox_id == scenario_run.devbox_id
106105

107-
# Cancel the scenario run
108-
scenario_result = bench_scenario_run.cancel()
109-
assert scenario_result.state in ["canceled", "completed"]
106+
# Cancel the scenario run
107+
scenario_result = scenario_run.cancel()
108+
assert scenario_result.state in ["canceled", "completed"]
110109

111110
# Cancel the benchmark run
112111
result = run.cancel()
113112
assert result.state in ["canceled", "completed"]
114113

115114
except Exception:
116115
# Ensure cleanup on any error
117-
try:
118-
for scenario_run in scenario_runs:
119-
sdk_client.api.scenarios.runs.cancel(scenario_run.id)
120-
sdk_client.api.benchmarks.runs.cancel(run.id)
121-
except Exception:
122-
pass
116+
if scenario_run:
117+
sdk_client.api.scenarios.runs.cancel(scenario_run.id)
118+
sdk_client.api.benchmarks.runs.cancel(run.id)
123119
raise
124120

125121

@@ -139,7 +135,7 @@ def test_list_runs(self, sdk_client: RunloopSDK) -> None:
139135
benchmarks = sdk_client.api.benchmarks.list(limit=1).benchmarks
140136

141137
if not benchmarks:
142-
pytest.skip("No benchmarks available to test")
138+
raise Exception("No benchmarks available to test")
143139

144140
benchmark_data = benchmarks[0]
145141

0 commit comments

Comments
 (0)