Skip to content

Stubtest: don't error if a module in a tests/ directory is missing from the stub #15725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
8 changes: 7 additions & 1 deletion mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,13 @@ def test_module(module_name: str) -> Iterator[Error]:
"""
stub = get_stub(module_name)
if stub is None:
if not is_probably_private(module_name.split(".")[-1]):
module_name_parts = module_name.split(".")
# Don't error for missing modules
# if the final part of the module name starts with a leading underscore,
# or the module is in a folder such as `test/`, `tests/` or `testing/`
if not is_probably_private(module_name_parts[-1]) and not (
set(module_name_parts) & {"test", "tests", "testing"}
):
runtime_desc = repr(sys.modules[module_name]) if module_name in sys.modules else "N/A"
yield Error(
[module_name], "failed to find stubs", MISSING, None, runtime_desc=runtime_desc
Expand Down