diff --git a/leapp/repository/actor_definition.py b/leapp/repository/actor_definition.py index 86ed811e9..5b0632b1c 100644 --- a/leapp/repository/actor_definition.py +++ b/leapp/repository/actor_definition.py @@ -33,7 +33,7 @@ class ActorCallContext(object): """ Wraps the actor execution into child process. """ - def __init__(self, definition, logger, messaging): + def __init__(self, definition, logger, messaging, within_pytest=False): """ :param definition: Actor definition :type definition: :py:class:`leapp.repository.actor_definition.ActorDefinition` @@ -45,6 +45,7 @@ def __init__(self, definition, logger, messaging): self.definition = definition self.logger = logger self.messaging = messaging + self.within_pytest = within_pytest @staticmethod def _do_run(stdin, logger, messaging, definition, args, kwargs): @@ -53,6 +54,10 @@ def _do_run(stdin, logger, messaging, definition, args, kwargs): sys.stdin = os.fdopen(stdin) except OSError: pass + self._do_run_impl(logger, messaging, definition, args, kwargs) + + @staticmethod + def _do_run_impl(logger, messaging, definition, args, kwargs): definition.load() with definition.injected_context(): target_actor = [actor for actor in get_actors() if actor.name == definition.name][0] @@ -62,17 +67,20 @@ def run(self, *args, **kwargs): """ Performs the actor execution in the child process. """ - try: - stdin = sys.stdin.fileno() - except UnsupportedOperation: - stdin = None - p = Process(target=self._do_run, args=(stdin, self.logger, self.messaging, self.definition, args, kwargs)) - p.start() - p.join() - if p.exitcode != 0: - raise LeappRuntimeError( - 'Actor {actorname} unexpectedly terminated with exit code: {exitcode}' - .format(actorname=self.definition.name, exitcode=p.exitcode)) + if self.within_pytest: + self._do_run_impl(self.logger, self.messaging, self.definition, args, kwargs) + else: + try: + stdin = sys.stdin.fileno() + except UnsupportedOperation: + stdin = None + p = Process(target=self._do_run, args=(stdin, self.logger, self.messaging, self.definition, args, kwargs)) + p.start() + p.join() + if p.exitcode != 0: + raise LeappRuntimeError( + 'Actor {actorname} unexpectedly terminated with exit code: {exitcode}' + .format(actorname=self.definition.name, exitcode=p.exitcode)) class ActorDefinition(object): @@ -168,8 +176,8 @@ def discover(self): tag.actors += (self,) return self._discovery - def __call__(self, messaging=None, logger=None): - return ActorCallContext(definition=self, messaging=messaging, logger=logger) + def __call__(self, messaging=None, logger=None, within_pytest=False): + return ActorCallContext(definition=self, messaging=messaging, logger=logger, within_pytest=within_pytest) @property def dialogs(self): diff --git a/leapp/snactor/fixture.py b/leapp/snactor/fixture.py index 7ed3518db..6c51b9892 100644 --- a/leapp/snactor/fixture.py +++ b/leapp/snactor/fixture.py @@ -101,7 +101,7 @@ def run(self): :return: None """ - self._actor(messaging=self._messaging).run() + self._actor(messaging=self._messaging, within_pytest=True).run() def messages(self): """