diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index 7fbd940e9..e963288b9 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -131,42 +131,38 @@ def run_stubtest( try: subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True) except subprocess.CalledProcessError as e: - print_error("fail\n") + print_error("fail") print_divider() - print("Commands run:", file=sys.stderr) + print("Commands run:") print_commands(dist, pip_cmd, stubtest_cmd, mypypath) print_divider() - print("Command output:\n", file=sys.stderr) + print("Command output:\n") print_command_output(e) + print_divider() + print("Python version: ", end="", flush=True) + ret = subprocess.run([sys.executable, "-VV"], capture_output=True) + print_command_output(ret) + print("\nRan with the following environment:") + ret = subprocess.run([pip_exe, "freeze", "--all"], capture_output=True) + print_command_output(ret) + + print_divider() + allowlist_path_relative = allowlist_path.relative_to(Path.cwd()) + if allowlist_path.exists(): + print(f'To fix "unused allowlist" errors, remove the corresponding entries from {allowlist_path_relative}') + print() + else: + print(f"Re-running stubtest with --generate-allowlist.\nAdd the following to {allowlist_path_relative}:") + ret = subprocess.run([*stubtest_cmd, "--generate-allowlist"], env=stubtest_env, capture_output=True) + print_command_output(ret) + print_divider() print(f"Upstream repository: {metadata.upstream_repository}") print(f"Typeshed source code: https://github.com/python/typeshed/tree/main/stubs/{dist.name}") - print("Python version: ", file=sys.stderr, end="", flush=True) - ret = subprocess.run([sys.executable, "-VV"], capture_output=True) - print_command_output(ret) - print("Ran with the following environment:", file=sys.stderr) - ret = subprocess.run([pip_exe, "freeze", "--all"], capture_output=True) - print_command_output(ret) - - allowlist_path_relative = allowlist_path.relative_to(Path.cwd()) - if allowlist_path.exists(): - print( - f'To fix "unused allowlist" errors, remove the corresponding entries from {allowlist_path_relative}', - file=sys.stderr, - ) - print(file=sys.stderr) - else: - print( - f"Re-running stubtest with --generate-allowlist.\nAdd the following to {allowlist_path_relative}:", - file=sys.stderr, - ) - ret = subprocess.run([*stubtest_cmd, "--generate-allowlist"], env=stubtest_env, capture_output=True) - print_command_output(ret) - print_divider() return False @@ -338,23 +334,21 @@ def setup_uwsgi_stubtest_command(dist: Path, venv_dir: Path, stubtest_cmd: list[ def print_commands(dist: Path, pip_cmd: list[str], stubtest_cmd: list[str], mypypath: str) -> None: - print(file=sys.stderr) - print(" ".join(pip_cmd), file=sys.stderr) - print(f"MYPYPATH={mypypath}", " ".join(stubtest_cmd), file=sys.stderr) - print(file=sys.stderr) + print() + print(" ".join(pip_cmd)) + print(f"MYPYPATH={mypypath}", " ".join(stubtest_cmd)) def print_command_failure(message: str, e: subprocess.CalledProcessError) -> None: print_error("fail") - print(file=sys.stderr) - print(message, file=sys.stderr) + print() + print(message) print_command_output(e) def print_command_output(e: subprocess.CalledProcessError | subprocess.CompletedProcess[bytes]) -> None: - print(e.stdout.decode(), end="", file=sys.stderr) - print(e.stderr.decode(), end="", file=sys.stderr) - print(file=sys.stderr) + print(e.stdout.decode(), end="") + print(e.stderr.decode(), end="") def main() -> NoReturn: diff --git a/tests/utils.py b/tests/utils.py index 9ed68f90c..345194ae7 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -41,19 +41,19 @@ def strip_comments(text: str) -> str: def print_command(cmd: str | Iterable[str]) -> None: if not isinstance(cmd, str): cmd = " ".join(cmd) - print(colored(f"Running: {cmd}", "blue"), file=sys.stderr) + print(colored(f"Running: {cmd}", "blue")) def print_error(error: str, end: str = "\n", fix_path: tuple[str, str] = ("", "")) -> None: error_split = error.split("\n") old, new = fix_path for line in error_split[:-1]: - print(colored(line.replace(old, new), "red"), file=sys.stderr) - print(colored(error_split[-1], "red"), end=end, file=sys.stderr) + print(colored(line.replace(old, new), "red")) + print(colored(error_split[-1], "red"), end=end) def print_success_msg() -> None: - print(colored("success", "green"), file=sys.stderr) + print(colored("success", "green")) def print_divider() -> None: @@ -61,9 +61,9 @@ def print_divider() -> None: This can be useful to divide terminal output into separate sections. """ - print(file=sys.stderr) - print("*" * 70, file=sys.stderr) - print(file=sys.stderr) + print() + print("*" * 70) + print() # ====================================================================