Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyrit/scenario/core/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,9 @@ async def worker_async() -> None:
if result.has_incomplete:
stop_event.set()
except Exception as exc:
exc.add_note(
f"Failed atomic attack {atomic_attack.atomic_attack_name!r} in scenario {self._name!r}."
)
outcomes.append(exc)
stop_event.set()
except BaseException:
Expand Down
16 changes: 13 additions & 3 deletions tests/unit/scenario/core/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,11 @@ async def _run(*args, **kwargs):
messages = sorted(str(e) for e in exc_info.value.exceptions)
assert messages == ["a boom", "b boom", "c boom"]
assert all(isinstance(e, RuntimeError) for e in exc_info.value.exceptions)
assert sorted(error.__notes__ for error in exc_info.value.exceptions) == [
["Failed atomic attack 'attack_run_1' in scenario 'Test Scenario'."],
["Failed atomic attack 'attack_run_2' in scenario 'Test Scenario'."],
["Failed atomic attack 'attack_run_3' in scenario 'Test Scenario'."],
]

async def test_single_failure_is_raised_directly_not_wrapped(
self, mock_atomic_attacks, sample_attack_results, mock_objective_target
Expand All @@ -2503,8 +2508,10 @@ async def test_single_failure_is_raised_directly_not_wrapped(
[sample_attack_results[i]], atomic_attack=mock_atomic_attacks[i]
)

failure = RuntimeError("solo boom")

async def bad_run(*a, **k):
raise RuntimeError("solo boom")
raise failure

mock_atomic_attacks[1].run_async = AsyncMock(side_effect=bad_run)

Expand All @@ -2521,10 +2528,13 @@ async def bad_run(*a, **k):
)
await scenario.initialize_async()

# Bare RuntimeError, not ExceptionGroup.
with pytest.raises(RuntimeError, match="solo boom"):
# Bare RuntimeError, not ExceptionGroup, with the original exception identity.
with pytest.raises(RuntimeError, match="solo boom") as exc_info:
await scenario.run_async()

assert exc_info.value is failure
assert exc_info.value.__notes__ == ["Failed atomic attack 'attack_run_2' in scenario 'Test Scenario'."]

async def test_max_concurrency_one_serializes_via_single_worker(
self, mock_atomic_attacks, sample_attack_results, mock_objective_target
):
Expand Down
Loading