-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
use getattr_static in spy instead of __getattributes__ #224
Conversation
tests/test_pytest_mock.py
Outdated
@@ -162,7 +162,7 @@ def test_mock_patch_dict_resetall(mocker: MockerFixture) -> None: | |||
], | |||
) | |||
def test_mocker_aliases(name: str, pytestconfig: Any) -> None: | |||
from pytest_mock.plugin import _get_mock_module | |||
from pytest_mock.plugin import _get_mock_module # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the pre-commit mypy run caught these imports with error: Cannot find implementation or library
but now the linting test is failing because of them...any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but I've moved _get_mock_module
and parse_ini_boolean
to a _util.py
module: this makes it clear this is not part of the API plus should fix that particular problem.
This also avoids having to use "#type:ignore" when importing them on tests.
Awesome, thanks for the contribution! |
Thanks again! |
Thanks for your help on this one! |
When attempting to use
mocker.spy
on a Stripe class in my project, I ran into this error:Here is the Customer source code for reference, a class inheriting from multiple parent classes and including some custom method wrappers.
While digging in order to fix this, I ended up at the stackoverflow question linked to in the original code which mentioned the
inspect
module's methodgetattr_static
available as of 3.2. This will accomplish the same behaviour as before, as well as work for a larger variety of classes.I also checked up on the bug that this workaround is there for in the first place, and it was fixed in 3.7 it seems, so eventually autospec can be true by default in theory.
I don't quite know how to reproduce the exact kind of class that would have caused this error in the first place, open to suggestions in order to add a test for it.