pytest-mypy-plugins icon indicating copy to clipboard operation
pytest-mypy-plugins copied to clipboard

Ignore mypy errors from site-packages imports

Open intgr opened this issue 2 years ago • 3 comments

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

intgr avatar Oct 05 '23 08:10 intgr

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

pytest --mypy-only-local-stub tests/mypy/

bricker avatar Nov 19 '23 02:11 bricker

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

Tinche avatar Dec 16 '23 15:12 Tinche

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

SukiCZ avatar Apr 25 '24 20:04 SukiCZ