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
Type checker fails with mocks #130
Labels
Milestone
Comments
fornellas
added
bug
Something isn't working
help wanted
Extra attention is needed
labels
Mar 25, 2020
david-caro
added a commit
to david-caro/TestSlide
that referenced
this issue
Mar 30, 2020
david-caro
added a commit
to david-caro/TestSlide
that referenced
this issue
Mar 30, 2020
We were not propely checking the signature validation when the parameters passed were mocks and failing with TypeError. This tries to extract the spec or template of the parameter to do the type checking allowing to pass mocks to the functions without failing the signature type validation. NOTE: this assumes that all unittest.mock mocks inherit from NonCallableMock, that assumption might change with time, though currently seems to be the case: ``` $ grep '^class .*Mock(' /usr/lib64/python3.7/unittest/mock.py class NonCallableMock(Base): class Mock(CallableMixin, NonCallableMock): class NonCallableMagicMock(MagicMixin, NonCallableMock): class MagicMock(MagicMixin, Mock): class PropertyMock(Mock): ``` Fixes facebook#130
david-caro
added a commit
to david-caro/TestSlide
that referenced
this issue
Mar 31, 2020
We were not propely checking the signature validation when the parameters passed were mocks and failing with TypeError. This tries to extract the spec or template of the parameter to do the type checking allowing to pass mocks to the functions without failing the signature type validation. NOTE: this assumes that all unittest.mock mocks inherit from NonCallableMock, that assumption might change with time, though currently seems to be the case: ``` $ grep '^class .*Mock(' /usr/lib64/python3.7/unittest/mock.py class NonCallableMock(Base): class Mock(CallableMixin, NonCallableMock): class NonCallableMagicMock(MagicMixin, NonCallableMock): class MagicMock(MagicMixin, Mock): class PropertyMock(Mock): ``` Fixes facebook#130
I sent a PR, not 100% sure if that's what you meant that was the problem xd |
PR is legit! This was exactly the problem, thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This PR added type checking for function calls. It works as expected, but it is failing when a call is made using a mock, but it should not.
Suggestion on how to fix this:
StrictMock
, get the giventemplate
(IIRC mock_callable already does this, there's a trick there).spec
.Using that:
The text was updated successfully, but these errors were encountered: