Skip to content

Commit

Permalink
Fixtures: Add support for Process inputs to submit_and_await (#5780)
Browse files Browse the repository at this point in the history
Currently the `submit_and_await` fixture did allow passing a `Process`
class, but not to provide the inputs needed to instantiate it. The
fixture now accepts `kwargs` which are used as the inputs in the case
that `submittable` is a process class.
  • Loading branch information
sphuber authored Nov 18, 2022
1 parent 38d40d5 commit 2f51a9f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions aiida/manage/tests/pytest_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import asyncio
import copy
import inspect
import pathlib
import shutil
import tempfile
Expand Down Expand Up @@ -288,20 +289,26 @@ def submit_and_await(started_daemon_client):
def _factory(
submittable: Process | ProcessBuilder | ProcessNode,
state: plumpy.ProcessState = plumpy.ProcessState.FINISHED,
timeout: int = 20
timeout: int = 20,
**kwargs
):
"""Submit a process and wait for it to achieve the given state.
:param submittable: A process, a process builder or a process node. If it is a process or builder, it is
submitted first before awaiting the desired state.
:param state: The process state to wait for, by default it waits for the submittable to be ``FINISHED``.
:param timeout: The time to wait for the process to achieve the state.
:param kwargs: If the ``submittable`` is a process class, it is instantiated with the ``kwargs`` as inputs.
:raises RuntimeError: If the process fails to achieve the specified state before the timeout expires.
"""
if not isinstance(submittable, ProcessNode):
if inspect.isclass(submittable) and issubclass(submittable, Process):
node = submit(submittable, **kwargs)
elif isinstance(submittable, ProcessBuilder):
node = submit(submittable)
else:
elif isinstance(submittable, ProcessNode):
node = submittable
else:
raise ValueError(f'type of submittable `{type(submittable)}` is not supported.')

start_time = time.time()

Expand Down

0 comments on commit 2f51a9f

Please sign in to comment.