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

        mod = __import__('__main__')

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

        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 NotImplentedError("module test functions not supported")
                    parent = mod
                    method = tcase

                result = run_test("%s:%s" % (mod.__file__, test),
                                  parent, method, nocap=nocap)

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

                    if MPI.COMM_WORLD.rank == 0:
                        for r in results:
                            if r.status != 'OK':
                                print r
                                break
                        else:
                            print r
                else:
                    print result

        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-Framework/openmdao.test/src/openmdao/test/mpiunittest.py/mpirun_tests