Skip to content

Commit 7c8e82f

Browse files
authored
Improve the output of tests/stubtest_third_party.py when it fails (#11763)
1 parent f4b89f5 commit 7c8e82f

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

scripts/stubsabot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U
498498
"Release": f"{pypi_info.pypi_root}/{relevant_version}",
499499
"Homepage": project_urls.get("Homepage"),
500500
"Repository": stub_info.upstream_repository,
501+
"Typeshed stubs": f"https://github.com/{TYPESHED_OWNER}/typeshed/tree/main/{stub_info.distribution}",
501502
"Changelog": project_urls.get("Changelog") or project_urls.get("Changes") or project_urls.get("Change Log"),
502503
}
503504
links = {k: v for k, v in maybe_links.items() if v is not None}

tests/stubtest_third_party.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from typing import NoReturn
1414

1515
from parse_metadata import NoSuchStubError, get_recursive_requirements, read_metadata
16-
from utils import PYTHON_VERSION, colored, get_mypy_req, print_error, print_success_msg
16+
from utils import PYTHON_VERSION, colored, get_mypy_req, print_divider, print_error, print_success_msg
1717

1818

1919
def run_stubtest(
@@ -24,7 +24,7 @@ def run_stubtest(
2424
metadata = read_metadata(dist_name)
2525
except NoSuchStubError as e:
2626
parser.error(str(e))
27-
print(f"{dist_name}... ", end="")
27+
print(f"{dist_name}... ", end="", flush=True)
2828

2929
stubtest_settings = metadata.stubtest_settings
3030
if stubtest_settings.skipped:
@@ -131,28 +131,44 @@ def run_stubtest(
131131
try:
132132
subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True)
133133
except subprocess.CalledProcessError as e:
134-
print_error("fail")
134+
print_error("fail\n")
135+
136+
print_divider()
137+
print("Commands run:")
135138
print_commands(dist, pip_cmd, stubtest_cmd, mypypath)
139+
140+
print_divider()
141+
print("Command output:\n")
136142
print_command_output(e)
137143

138-
print("Python version: ", file=sys.stderr)
144+
print_divider()
145+
print(f"Upstream repository: {metadata.upstream_repository}")
146+
print(f"Typeshed source code: https://github.com/python/typeshed/tree/main/stubs/{dist.name}")
147+
148+
print("Python version: ", file=sys.stderr, end="", flush=True)
139149
ret = subprocess.run([sys.executable, "-VV"], capture_output=True)
140150
print_command_output(ret)
141-
142151
print("Ran with the following environment:", file=sys.stderr)
143152
ret = subprocess.run([pip_exe, "freeze", "--all"], capture_output=True)
144153
print_command_output(ret)
145154

155+
allowlist_path_relative = allowlist_path.relative_to(Path.cwd())
146156
if allowlist_path.exists():
147157
print(
148-
f'To fix "unused allowlist" errors, remove the corresponding entries from {allowlist_path}', file=sys.stderr
158+
f'To fix "unused allowlist" errors, remove the corresponding entries from {allowlist_path_relative}',
159+
file=sys.stderr,
149160
)
150161
print(file=sys.stderr)
151162
else:
152-
print(f"Re-running stubtest with --generate-allowlist.\nAdd the following to {allowlist_path}:", file=sys.stderr)
163+
print(
164+
f"Re-running stubtest with --generate-allowlist.\nAdd the following to {allowlist_path_relative}:",
165+
file=sys.stderr,
166+
)
153167
ret = subprocess.run([*stubtest_cmd, "--generate-allowlist"], env=stubtest_env, capture_output=True)
154168
print_command_output(ret)
155169

170+
print_divider()
171+
156172
return False
157173
else:
158174
print_success_msg()

tests/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ def print_success_msg() -> None:
5656
print(colored("success", "green"))
5757

5858

59+
def print_divider() -> None:
60+
"""Print a row of * symbols across the screen.
61+
62+
This can be useful to divide terminal output into separate sections.
63+
"""
64+
print("*" * 70)
65+
66+
5967
# ====================================================================
6068
# Dynamic venv creation
6169
# ====================================================================

0 commit comments

Comments
 (0)