Skip to content

Commit

Permalink
Merge pull request #2 from landerlini/landerlini_do_not_hide_exceptio…
Browse files Browse the repository at this point in the history
…ns_in_context

Added reproducer for issue landerlini/hopaas#26 and fixed it
  • Loading branch information
mbarbetti authored Oct 21, 2022
2 parents 7158621 + 7667822 commit 0424d60
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hopaas_client/Study.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ def trial(self):

try:
yield trial
except (Exception, KeyboardInterrupt):
except KeyboardInterrupt:
trial.loss = None
except Exception as e:
trial.loss = None
raise e
finally:
if trial.loss is not None:
if not trial.should_prune:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_Errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import random
import pytest

RANDOM_CODE = random.randint(0, 10000)


@pytest.fixture
def study():
from hopaas_client import Study
study = Study('TEST::Study::study', dict(some_value=RANDOM_CODE))
return study


################################################################################


def test_trial_context_error(study):
try:
with study.trial() as trial:
print(1 // 0)
except ZeroDivisionError:
return True
else:
raise AssertionError("A ZeroDivisionError was masked")



0 comments on commit 0424d60

Please sign in to comment.