Repository: matplotlib/matplotlib
File: lib/matplotlib/testing/__init__.py (Python)

Code before:
    --------
    subprocess.run

    Raises
    ------
    pytest.xfail
        If platform is Cygwin and subprocess reports a fork() failure.
    """
    if capture_output:
        stdout = stderr = subprocess.PIPE
    try:
        proc = subprocess.run(
            command, env=env,
            timeout=timeout, check=check,
            stdout=stdout, stderr=stderr,
            text=text
        )
    except BlockingIOError:
        if sys.platform == "cygwin":
            # Might want to make this more specific
            import pytest
            pytest.xfail("Fork failure")
        raise
    except subprocess.CalledProcessError as e:
        import pytest
        pytest.xfail(f"Subprocess failed with exit code {e.returncode}:\n{e.stdout}\n{e.stderr}")
    return proc


def subprocess_run_helper(func, *args, timeout, extra_env=None):
    """
    Run a function in a sub-process.

    Parameters
    ----------
    func : function
        The function to be run.  It must be in a module that is importable.
    *args : str
        Any additional command line arguments to be passed in
        the first argument to ``subprocess.run``.
    extra_env : dict[str, str]
        Any additional environment variables to be set for the subprocess.
    """
    target = func.__name__
    module = func.__module__
    file = func.__code__.co_filename
    proc = subprocess_run_for_testing(
        [
            sys.executable,
            "-c",
            f"import importlib.util;"

Review comment (bug):
This should be a plain fail not an xfail, also made it a bit more verbose to make stdout and stderr output easier to read:

```suggestion
        pytest.fail(
            f"Subprocess failed with exit code {e.returncode}:\n\n"
            f"STDOUT:\n{e.stdout}\n\nSTDERR:\n{e.stderr}")
```

Code after:
    --------
    subprocess.run

    Raises
    ------
    pytest.xfail
        If platform is Cygwin and subprocess reports a fork() failure.
    """
    if capture_output:
        stdout = stderr = subprocess.PIPE
    try:
        proc = subprocess.run(
            command, env=env,
            timeout=timeout, check=check,
            stdout=stdout, stderr=stderr,
            text=text
        )
    except BlockingIOError:
        if sys.platform == "cygwin":
            # Might want to make this more specific
            import pytest
            pytest.xfail("Fork failure")
        raise
    except subprocess.CalledProcessError as e:
        if e.stdout:
            _log.error(f"Subprocess output:\n{e.stdout}")
        if e.stderr:
            _log.error(f"Subprocess error:\n{e.stderr}")
        raise e
    if proc.stdout:
        _log.debug(f"Subprocess output:\n{proc.stdout}")
    if proc.stderr:
        _log.debug(f"Subprocess error:\n{proc.stderr}")
    return proc


def subprocess_run_helper(func, *args, timeout, extra_env=None):
    """
    Run a function in a sub-process.

    Parameters
    ----------
    func : function
        The function to be run.  It must be in a module that is importable.
    *args : str
        Any additional command line arguments to be passed in
        the first argument to ``subprocess.run``.
    extra_env : dict[str, str]
        Any additional environment variables to be set for the subprocess.
    """
    target = func.__name__