Make gmxcli pytest fixture more robust.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Mon, 9 Sep 2019 13:23:04 +0000 (16:23 +0300)
committerEric Irrgang <ericirrgang@gmail.com>
Tue, 10 Sep 2019 16:27:41 +0000 (18:27 +0200)
Look for multiple possible `gmx` command line executables.

This change may be followed up, amended, replaced, or superseded by
change Icefe89e97009110be55dc8e1f3db5726ec1fe53a but is necessary
now to support child changes under review.

Refs #2961

Change-Id: I7d9d830c1b16fbd2af86aded3f1fea5f3a63307f

python_packaging/src/test/conftest.py

index 997c5e48fe440e2f63de4d817b4481bc78e910f7..1ef83a32ab5a0e3c61362f26408e64effb6d878a 100644 (file)
@@ -93,23 +93,25 @@ def gmxcli():
     # TODO: (#2896) Find a more canonical way to identify the GROMACS commandline wrapper binary.
     #  We should be able to get the GMXRC contents and related hints from a gmxapi
     #  package resource or from module attributes of a ``gromacs`` stub package.
-    command = shutil.which('gmx')
-    if command is None:
-        gmxbindir = os.getenv('GMXBIN')
-        if gmxbindir is None:
-            gromacsdir = os.getenv('GROMACS_DIR')
-            if gromacsdir is not None and gromacsdir != '':
-                gmxbindir = os.path.join(gromacsdir, 'bin')
-        if gmxbindir is None:
-            gmxapidir = os.getenv('gmxapi_DIR')
-            if gmxapidir is not None and gmxapidir != '':
-                gmxbindir = os.path.join(gmxapidir, 'bin')
-        if gmxbindir is not None:
-            gmxbindir = os.path.abspath(gmxbindir)
-            command = shutil.which('gmx', path=gmxbindir)
-        else:
-            message = "Tests need 'gmx' command line tool, but could not find it on the path."
-            raise RuntimeError(message)
+    allowed_command_names = ['gmx', 'gmx_mpi']
+    command = None
+    for command_name in allowed_command_names:
+        if command is not None:
+            break
+        command = shutil.which(command_name)
+        if command is None:
+            gmxbindir = os.getenv('GMXBIN')
+            if gmxbindir is None:
+                gromacsdir = os.getenv('GROMACS_DIR')
+                if gromacsdir is not None and gromacsdir != '':
+                    gmxbindir = os.path.join(gromacsdir, 'bin')
+            if gmxbindir is None:
+                gmxapidir = os.getenv('gmxapi_DIR')
+                if gmxapidir is not None and gmxapidir != '':
+                    gmxbindir = os.path.join(gmxapidir, 'bin')
+            if gmxbindir is not None:
+                gmxbindir = os.path.abspath(gmxbindir)
+                command = shutil.which(command_name, path=gmxbindir)
     if command is None:
         message = "Tests need 'gmx' command line tool, but could not find it on the path."
         raise RuntimeError(message)