@@ -33,7 +33,7 @@ class ActorCallContext(object):
3333 """
3434 Wraps the actor execution into child process.
3535 """
36- def __init__ (self , definition , logger , messaging ):
36+ def __init__ (self , definition , logger , messaging , within_pytest = False ):
3737 """
3838 :param definition: Actor definition
3939 :type definition: :py:class:`leapp.repository.actor_definition.ActorDefinition`
@@ -45,6 +45,7 @@ def __init__(self, definition, logger, messaging):
4545 self .definition = definition
4646 self .logger = logger
4747 self .messaging = messaging
48+ self .within_pytest = within_pytest
4849
4950 @staticmethod
5051 def _do_run (stdin , logger , messaging , definition , args , kwargs ):
@@ -53,6 +54,10 @@ def _do_run(stdin, logger, messaging, definition, args, kwargs):
5354 sys .stdin = os .fdopen (stdin )
5455 except OSError :
5556 pass
57+ self ._do_run_impl (logger , messaging , definition , args , kwargs )
58+
59+ @staticmethod
60+ def _do_run_impl (logger , messaging , definition , args , kwargs )
5661 definition .load ()
5762 with definition .injected_context ():
5863 target_actor = [actor for actor in get_actors () if actor .name == definition .name ][0 ]
@@ -62,17 +67,20 @@ def run(self, *args, **kwargs):
6267 """
6368 Performs the actor execution in the child process.
6469 """
65- try :
66- stdin = sys .stdin .fileno ()
67- except UnsupportedOperation :
68- stdin = None
69- p = Process (target = self ._do_run , args = (stdin , self .logger , self .messaging , self .definition , args , kwargs ))
70- p .start ()
71- p .join ()
72- if p .exitcode != 0 :
73- raise LeappRuntimeError (
74- 'Actor {actorname} unexpectedly terminated with exit code: {exitcode}'
75- .format (actorname = self .definition .name , exitcode = p .exitcode ))
70+ if self .within_pytest :
71+ self ._do_run_impl (self .logger , self .messaging , self .definition , args , kwargs )
72+ else :
73+ try :
74+ stdin = sys .stdin .fileno ()
75+ except UnsupportedOperation :
76+ stdin = None
77+ p = Process (target = self ._do_run , args = (stdin , self .logger , self .messaging , self .definition , args , kwargs ))
78+ p .start ()
79+ p .join ()
80+ if p .exitcode != 0 :
81+ raise LeappRuntimeError (
82+ 'Actor {actorname} unexpectedly terminated with exit code: {exitcode}'
83+ .format (actorname = self .definition .name , exitcode = p .exitcode ))
7684
7785
7886class ActorDefinition (object ):
@@ -168,8 +176,8 @@ def discover(self):
168176 tag .actors += (self ,)
169177 return self ._discovery
170178
171- def __call__ (self , messaging = None , logger = None ):
172- return ActorCallContext (definition = self , messaging = messaging , logger = logger )
179+ def __call__ (self , messaging = None , logger = None , within_pytest = False ):
180+ return ActorCallContext (definition = self , messaging = messaging , logger = logger , within_pytest = within_pytest )
173181
174182 @property
175183 def dialogs (self ):
0 commit comments