diff --git a/ops/_main.py b/ops/_main.py index 01b4740b0..d82fdc597 100644 --- a/ops/_main.py +++ b/ops/_main.py @@ -508,7 +508,7 @@ def _get_event_to_emit(self, event_name: str) -> Optional[ops.framework.BoundEve return getattr(self.charm.on, event_name) except AttributeError: logger.debug('Event %s not defined for %s.', event_name, self.charm) - # If the event is not defined, return None. + return None def _emit_charm_event(self, event_name: str): """Emits a charm event based on a Juju event name. @@ -522,10 +522,12 @@ def _emit_charm_event(self, event_name: str): # If the event is not supported by the charm implementation, do # not error out or try to emit it. This is to support rollbacks. - if event_to_emit is not None: - args, kwargs = _get_event_args(self.charm, event_to_emit, self._juju_context) - logger.debug('Emitting Juju event %s.', event_name) - event_to_emit.emit(*args, **kwargs) + if event_to_emit is None: + return + + args, kwargs = _get_event_args(self.charm, event_to_emit, self._juju_context) + logger.debug('Emitting Juju event %s.', event_name) + event_to_emit.emit(*args, **kwargs) def _commit(self): """Commit the framework and gracefully teardown.""" diff --git a/testing/src/scenario/_consistency_checker.py b/testing/src/scenario/_consistency_checker.py index 156a16ccc..5d2620e52 100644 --- a/testing/src/scenario/_consistency_checker.py +++ b/testing/src/scenario/_consistency_checker.py @@ -178,6 +178,7 @@ def check_event_consistency( "(e.g. a relation event, or a workload event), you might get some false-negative " "consistency checks.", ) + return Results(errors, warnings) if event._is_relation_event: _check_relation_event(charm_spec, event, state, errors, warnings)