def run_command(cmd: str) -> tuple[int, str]:
    """Run a command in a subprocess.

    Returns the exit status code and the combined stdout and stderr.

    """
    # Subprocesses are expensive, but convenient, and so may be over-used in
    # the test suite.  Use these lines to get a list of the tests using them:
    if 0:  # pragma: debugging
        pth = "/tmp/processes.txt"                      # type: ignore[unreachable]
        with open(pth, "a", encoding="utf-8") as proctxt:
            print(os.getenv("PYTEST_CURRENT_TEST", "unknown"), file=proctxt, flush=True)

    # Type checking trick due to "unreachable" being set
    _locale_type_erased: Any = locale

    encoding = os.device_encoding(1) or (
        _locale_type_erased.getpreferredencoding()
        if sys.version_info < (3, 11)
        else _locale_type_erased.getencoding()
    )

    # In some strange cases (PyPy3 in a virtualenv!?) the stdout encoding of
    # the subprocess is set incorrectly to ascii.  Use an environment variable
    # to force the encoding to be the same as ours.
    sub_env = dict(os.environ)
    sub_env['PYTHONIOENCODING'] = encoding

    proc = subprocess.Popen(
        cmd,
        shell=True,
        env=sub_env,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
    )
    output, _ = proc.communicate()
    status = proc.returncode

    # Get the output, and canonicalize it to strings with newlines.
    output_str = output.decode(encoding).replace("\r", "")
    return status, output_str
Run a command in a subprocess.

    Returns the exit status code and the combined stdout and stderr.

    
tests/helpers.py