Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Run using
This test compares the stdlib stubs against the objects at runtime. Because of
this, the output depends on which version of Python and on what kind of system
it is run.
To check specific modules instead of the entire standard library, pass their
import names, for example `python tests/stubtest_stdlib.py getopt`.
As such, if you run this test locally, it may complain about system-specific
differences (in e.g., `socket`) that the type system cannot capture or our stubtest settings
in CI do not account for. If you run into this issue, consider opening a draft PR and letting CI
Expand Down
5 changes: 3 additions & 2 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def main() -> None:
stubtest_result: subprocess.CompletedProcess[bytes] | None = None

print("\nRunning pre-commit...")
pre_commit_result = subprocess.run(["pre-commit", "run", "--files", *path.rglob("*")], check=False)
files = [path] if path.is_file() else list(path.rglob("*"))
pre_commit_result = subprocess.run(["pre-commit", "run", "--files", *files], check=False)

print("\nRunning check_typeshed_structure.py...")
check_structure_result = subprocess.run([sys.executable, "tests/check_typeshed_structure.py"], check=False)
Expand Down Expand Up @@ -154,7 +155,7 @@ def main() -> None:
if mypy_result.returncode == 0:
if folder == "stdlib":
print("\nRunning stubtest...")
stubtest_result = subprocess.run([sys.executable, "tests/stubtest_stdlib.py", stub], check=False)
stubtest_result = subprocess.run([sys.executable, "tests/stubtest_stdlib.py", Path(stub).stem], check=False)
else:
if run_stubtest:
print("\nRunning stubtest...")
Expand Down
10 changes: 7 additions & 3 deletions tests/stubtest_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

import subprocess
import sys
from collections.abc import Sequence
from pathlib import Path

from ts_utils.paths import TS_BASE_PATH, allowlists_path
from ts_utils.utils import allowlist_stubtest_arguments


def run_stubtest(typeshed_dir: Path) -> int:
def run_stubtest(typeshed_dir: Path, modules: Sequence[str] = ()) -> int:
# Note when stubtest imports distutils, it will likely actually import setuptools._distutils
# This is fine because we don't care about distutils and allowlist all errors from it
# https://github.com/python/typeshed/pull/10253#discussion_r1216712404
Expand All @@ -26,13 +27,16 @@ def run_stubtest(typeshed_dir: Path) -> int:
sys.executable,
"-m",
"mypy.stubtest",
"--check-typeshed",
*(modules if modules else ["--check-typeshed"]),
"--show-traceback",
"--strict-type-check-only",
"--custom-typeshed-dir",
str(typeshed_dir),
*allowlist_stubtest_arguments("stdlib"),
]
if modules:
# Entries for modules outside this selection are expected to be unused.
cmd.append("--ignore-unused-allowlist")
print(" ".join(cmd), file=sys.stderr)
try:
subprocess.run(cmd, check=True)
Expand All @@ -56,4 +60,4 @@ def run_stubtest(typeshed_dir: Path) -> int:


if __name__ == "__main__":
sys.exit(run_stubtest(typeshed_dir=TS_BASE_PATH))
sys.exit(run_stubtest(typeshed_dir=TS_BASE_PATH, modules=sys.argv[1:]))
Loading