typeddjango / pytest-mypy-plugins

pytest plugin for testing mypy types, stubs, and plugins
https://pypi.org/project/pytest-mypy-plugins/
MIT License
100 stars 26 forks source link

Ignore mypy errors from site-packages imports #134

Open intgr opened 11 months ago

intgr commented 11 months ago

Mypy by default silences all errors that come from installed third party packages in site-packages. This can be disabled with the --no-silence-site-packages flag.

However, they are not silenced in pytest-mypy-plugins tests and I don't see a way to enable that behavior.

For example in https://github.com/typeddjango/djangorestframework-stubs/pull/480 I enabled disallow_untyped_defs and disallow_incomplete_defs options, but then I got mypy errors from yaml-stubs package:

_________________________________________________________________________________________________ test_override_get_permissions _________________________________________________________________________________________________
/Users/marti.raudsepp/own/djangorestframework-stubs/tests/typecheck/test_views.yml:69: 
E   pytest_mypy_plugins.utils.TypecheckAssertionError: Output is not expected: 
E   Actual:
E     ../../../../../../[...]/djangorestframework-stubs/.venv/lib/python3.11/site-packages/yaml-stubs/__init__.pyi:29: error: Function is missing a type annotation (diff)
E     ../../../../../../[...]/djangorestframework-stubs/.venv/lib/python3.11/site-packages/yaml-stubs/__init__.pyi:30: error: Function is missing a return type annotation (diff)
... lots more ...

As a work-around, I can just suppress these in mypy.ini

[mypy-yaml.*]
disallow_untyped_defs = false
disallow_incomplete_defs = false
bricker commented 10 months ago

Passing the option --mypy-only-local-stub fixes this issue, eg:

pytest --mypy-only-local-stub tests/mypy/
Tinche commented 9 months ago

I would argue this behavior should be the default. It's more useful and it's the default in Mypy, after all.

SukiCZ commented 4 months ago

Should the pytest --mypy-only-local-stub be mentioned in CONTRIBUTING.md? Or the flag defined in pytest.ini/mypy.ini?