def mpirun_tests(args=None):
        if args is None:
            args = sys.argv[1:]

        mod = __import__('__main__')

        if '-ns' in args:
            nocap = False
        else:
            nocap = True

        tests = [n for n in args if not n.startswith('-')]
        options = [n for n in args if n.startswith('-')]

        if tests:
            for test in tests:
                tcase, _, method = test.partition('.')
                if method:
                    parent = getattr(mod, tcase)(methodName=method)
                    if hasattr(parent, 'N_PROCS') and not under_mpirun():
                        retcode = run_in_sub(getattr(mod, tcase), test, options)
                        continue
                else:
                    raise NotImplementedError("module test functions not supported yet")
                    #parent = mod
                    #method = tcase

                tspec = "%s:%s" % (mod.__file__, test)
                if MPI.COMM_WORLD.rank == 0:
                    sys.stdout.write("%s ... " % tspec)
                result = run_test(tspec, parent, method, nocap=nocap)

                if under_mpirun():
                    results = MPI.COMM_WORLD.gather(result, root=0)

                    if MPI.COMM_WORLD.rank == 0:
                        for i,r in enumerate(results):
                            if r.status != 'OK':
                                sys.stdout.write("%s\nERROR in rank %d:\n" % (r.status, i))
                                sys.stdout.write("%s\n" % r.err_msg)
                                break
                        else:
                            sys.stdout.write("%s\n" % r.status)
                else:
                    sys.stdout.write("%s\n" % r.status)

        else: # find all test methods in the file and mpi run ourselves for each one

            for k,v in getmembers(mod, isclass):
                if issubclass(v, TestCase):
                    for n, method in getmembers(v, ismethod):
                        if n.startswith('test_'):
                            testspec = k+'.'+n
                            if not hasattr(v, 'N_PROCS'):
                                print(run_test(testspec, v(methodName=n), n, nocap=nocap))
                            else:
                                retcode = run_in_sub(v, testspec, options)
This is used in the "if __name__ == '__main__'" block to run all
dataset/ETHPy150Open OpenMDAO/OpenMDAO/openmdao/test/mpi_util.py/mpirun_tests