def METHOD_NAME(cmd, cwd, env):
    """
    Execute a process in a test case.  If the run is successful do not bloat
    the test output, but in case of any failure dump stdout and stderr.
    Returns (stdout, stderr) pair of strings.
    """
    def show(out, err):
        print("\nTEST execute stdout:\n")
        print(out)
        print("\nTEST execute stderr:\n")
        print(err)
    cmd_log = ' '.join([shlex.quote(x) for x in cmd])
    try:
        # In case the Popen fails, have these initialized.
        out = ''
        err = ''
        proc = subprocess.Popen(
            cmd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=cwd,
            env=env,
            encoding="utf-8",
            errors="ignore")
        out, err = proc.communicate()
        if proc.returncode != 0:
            show(out, err)
            print(f'Unsuccessful run: {cmd_log}')
            print(proc.returncode)
        return out, err, proc.returncode
    except OSError as oerr:
        print(oerr)
        show(out, err)
        print(f'Failed to run: {cmd_log}')
        raise