+@pytest.fixture(scope='session')
+def gmxconfig():
+ try:
+ from importlib.resources import open_text
+ with open_text('gmxapi', 'gmxconfig.json') as textfile:
+ config = json.load(textfile)
+ except ImportError:
+ # TODO: Remove this when we require Python 3.7
+ try:
+ # A backport of importlib.resources is available as importlib_resources
+ # with a somewhat different interface.
+ from importlib_resources import files, as_file
+
+ source = files('gmxapi').joinpath('gmxconfig.json')
+ with as_file(source) as gmxconfig:
+ with open(gmxconfig, 'r') as fp:
+ config = json.load(fp)
+ except ImportError:
+ config = None
+ yield config
+
+@pytest.fixture(scope='session')
+def mdrun_kwargs(request, gmxconfig):
+ """pytest fixture to provide a mdrun_kwargs dictionary for the mdrun ResourceManager.
+ """
+ from gmxapi.simulation.mdrun import ResourceManager as _ResourceManager
+ if gmxconfig is None:
+ raise RuntimeError('--threads argument requires a usable gmxconfig.json')
+ arg = request.config.getoption('--threads')
+ if arg is None:
+ return {}
+ mpi_type = gmxconfig['gmx_mpi_type']
+ if mpi_type is not None and mpi_type == "tmpi":
+ kwargs = {'threads': int(arg)}
+ else:
+ kwargs = {}
+ # TODO: (#3718) Normalize the handling of run-time arguments.
+ _ResourceManager.mdrun_kwargs = dict(**kwargs)
+ return kwargs
+