You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pytest_mock has no stubs in typeshed, which is why mocker.patch() returns Any. Previously, Mock was aliased to Any, which is why this did not cause errors before. Possible solutions:
tests/test_validation.py: note: In function "mock_open_valid_file":
tests/test_validation.py:28:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mocker.patch("builtins.open", mocker.mock_open(read_data="[x]\na = 3"))
^
tests/test_validation.py:28:42: error: "MockFixture" has no attribute "mock_open" [attr-defined]
return mocker.patch("builtins.open", mocker.mock_open(read_data="[x]\na = 3"))
^
tests/test_validation.py: note: In function "mock_open_invalid_file":
tests/test_validation.py:34:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mocker.patch(
^
tests/test_validation.py:35:26: error: "MockFixture" has no attribute "mock_open" [attr-defined]
"builtins.open", mocker.mock_open(read_data="[x]\na = 3\n[x]\na = 3")
^
Found 4 errors in 1 file (checked 8 source files)
@staticdev Do you run mypy with MYPYPATH? In our internal codebase, the stubs are in a sub-directory stubs and mypy is called like this: MYPYPATH=stubs mypy ...
@srittau yes, I put them on the path. And if I remove the folder I get even more errors:
tests/test_validation.py:5:1: error: Skipping analyzing 'pytest_mock': found module but no type
hints or library stubs [import]
from pytest_mock import MockFixture
^
tests/test_validation.py: note: In function "mock_tomlkit_parse":
tests/test_validation.py:14:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mocker.patch("tomlkit.parse")
^
tests/test_validation.py: note: In function "mock_tomlkit_parse_exception":
tests/test_validation.py:22:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mock
^
tests/test_validation.py: note: In function "mock_open_valid_file":
tests/test_validation.py:28:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mocker.patch("builtins.open", mocker.mock_open(read_data="[x]\na = 3"))
^
tests/test_validation.py: note: In function "mock_open_invalid_file":
tests/test_validation.py:34:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mocker.patch(
^
tests/test_main.py:6:1: error: Skipping analyzing 'pytest_mock': found module but no type hints or
library stubs [import]
from pytest_mock import MockFixture
^
tests/test_main.py:6:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
tests/test_main.py: note: In function "mock_validation_validate_extension":
tests/test_main.py:20:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mocker.patch("toml_validator.validation.validate_extension")
^
tests/test_main.py: note: In function "mock_validation_validate_toml_no_error":
tests/test_main.py:28:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mock
^
tests/test_main.py: note: In function "mock_validation_validate_toml_with_error":
tests/test_main.py:36:5: error: Returning Any from function declared to return "Mock"
[no-any-return]
return mock
^
Found 9 errors in 2 files (checked 8 source files)
I think the argument mocker.mock_open is breaking the interface in this case.
Activity
JelleZijlstra commentedon Jun 25, 2020
I suppose this is caused by #3871?
staticdev commentedon Jun 25, 2020
@JelleZijlstra is there a release with this fix so I can test?
srittau commentedon Jun 25, 2020
pytest_mock has no stubs in typeshed, which is why
mocker.patch()returnsAny. Previously,Mockwas aliased toAny, which is why this did not cause errors before. Possible solutions:cast(Mock, ...)on the return value.# type: ignore.staticdev commentedon Jun 25, 2020
@srittau so adding type-hints to pytest_mock also solves the problem?
It seems like a more permanent solution and this lib has like 300 lines of code.
srittau commentedon Jun 25, 2020
That would be the best solution, of course.
staticdev commentedon Jun 26, 2020
@srittau while it is not accepted by pytest_mock. I tried adding the stubs for pytest_mock from https://github.com/srittau/python-stubs/tree/master/stubs/pytest_mock.
I am still getting a related errors:
The draft PR is here staticdev/toml-validator#110
Can you also help me with that one?
srittau commentedon Jun 26, 2020
@staticdev Do you run mypy with
MYPYPATH? In our internal codebase, the stubs are in a sub-directorystubsand mypy is called like this:MYPYPATH=stubs mypy ...staticdev commentedon Jun 26, 2020
@srittau yes, I put them on the path. And if I remove the folder I get even more errors:
I think the argument
mocker.mock_openis breaking the interface in this case.